Home >Backend Development >PHP Tutorial >Database operations explained
? & Lt;? PHP // ThinkPHP database operation
// Configure an array form using common configuration and database configuration two combinations and
$ arr1 = array (
// 'configuration item' = & gt; The four methods of pathinfo 0, 1, 2, 3 are commonly used 0, 1
"URL_MODEL"=>0,
//URL_PATHINFO normal mode
"URL_PATHINFO_MODEL"=>2,
);
$arr2=array(
// The database configuration '' db_type '= & gt;' mysql ', // database type
' db_host '= & gt;' localhost ', // server address
' db_name '= & gt; => '3306', // Port
'DB_PREFIX' => 'think_', // Database table prefix
'DB_FIELDS_CACHE' => false, // Turn off field caching
);
return array_merge($arr1,$arr2);
//2, database consistency Operation Commonly used add, delete, modify and check
//Check find() select() $user->where("age gt 18 and sex eq 1")->order("id desc")->group("user_id ,creat_time")->limit(10)->select(); $user->where("id=1")->find();// Use when querying only one piece of data
$user ->field("id,name")->select();//field query $user->field("message","id",true)->select();//field Query all fields except message and id $Model->field('title,email,content')->create();//The field method is used in combination with the create method to complete the field legality detection of form submission
$user->field(array('id','concat(name,'-',id)'=>'truename','LEFT(title,7)'=>'sub_title'))-> ;select(); //
$user->table("think_user user,think_user_message m")->field("user.id as uid,m.id as mid,user.name")->where ("user.id=m.id")->select(); //Multiple table query
$user->join("think_message ON think_user.id=think_message.uid")->select (); //Pay attention to the master-slave table
//Insert add Insert data $user->create($data);//Get form data and push it into an array
$user->add($ data); //$data must be a field in the database, otherwise print_r will not output the data
$user->field("name")->add();//Add field method representation before the Add method Only the name field is allowed to be inserted and no other fields are inserted. It plays a filtering role
$user->data($data)->filter("srip_tags")->add();//Yes The value is processed. Remove the label name and it becomes name
//Change save to modify the data
$data["name"]="zhou"; $data["id" ]="2";
$user->where("id=5")->data($data)->save();Save modified data according to conditions
$ user->where("id=5")->field("name")->filter("strip_tags")->save();Modify and filter data according to conditions
<span></span><p><span> $user->save($data);<br> <br> //delect deletion method<br> $user->delect();<br> $user->where("status=1")->order(" creat_time desc")->limit("10")->delect();</span></p>
<p><br></p>
<p>
The above has introduced the general explanation of database operations, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials. </p>
<p>
</p>