Two data sheets
Here's how:
/********************** Database Operation ********************/
Add Data//////////
Populating data
$NewUser ["username"]= "Zhangsan";
$NewUser ["pwd"]= "123";
$NewUser ["Sex"]=1;
$NewUser ["Age"]=23;
$NewUser ["Type"]=1;
instance table pair Sex
$User =m ("User");
The Add method adds a piece of data to the table and returns the inserted index value
$result = $User->add ($NewUser);
Insert Data End///////
Find Data//////////
Single Query
$User =m ("User");
$result = $User->where ("Sex=1")->find ();
foreach ($result as $key = = $value) {
echo $key. " ==> ". $value." <br/> ";
}
More than one query
$User =m ("User");
$result = $User->where ("Sex=1")->select ();
foreach ($result as $item) {
foreach ($item as $key = = $value) {
echo $key. " ==> ". $value." <br/> ";
}
echo "
}
Find Data End//////////
Update////////
$User =m ("User");
Fill in the data you want to change
$NewData ["username"]= "Wanghe";
Define constraints and populate the data, then save, return the changed index value
$result = $User->where ("id=1")->data ($NewData)->save ();
echo $result;
Update End////////
Delete Operation///////////
$User =m ("User");
Define the constraint, return the changed index value
$reslut = $User->where ("id=1")->delete ();
Echo $reslut;
Delete Operation End///////////
Simple paging Operation//////////
$User =m ("User");
$result = $User->page ("0". ", 2")->select ();
Var_dump ($result);
Simple paging operation End//////////
Transaction Operation/////////////
$User =m ("User");
$User->starttrans ();//Start transaction
$reslut 1= $User->query ("INSERT into User (username) VALUES (' wangwu1 ')");//executable statement
$reslut 2= $User->query ("INSERT into User (username2) VALUES (' Wangwu2 ')");//non-executable statement
if ($reslut 1>0&& $reslut 2>0) {
$User->commit ();//Submit data
}else{
$User->rollback ();//Rollback
}
Transaction Operation End/////////////
Multi-Table Query/////////////
$User =new Model ("User");
$reslut = $User->table (' User,zhuwu ')->where (' User.type = Zhuwu.typeid ')->select ();
Var_dump ($reslut);
Multi-table Query end////////////
PHP thinkphp Data Manipulation curd