This article describes the simple batch query function of ThinkPHP5 framework. Share it for your reference, as follows:
TP5's EXP, batch query, aggregation query, etc.
<!--more--> //Use EXP conditional expression to indicate that the following is a native SQL expression$result = Db::table('think_inno')->where('id','exp',"<10 and name='asd'")->select(); dump($result); // Use and or for mixed query$result = Db::table('think_inno') ->where('name','like','%think%') //name is similar to %thinkphp%->where('id',['in',[1,2,3]],['>=',1],'or') //id is between 1~3, or id>=1->limit(2) ->select(); //Batch query$result = Db::table('think_inno') //Batch query->where(['id' => [['in',[1,2,3]],['>=',1],'or'], 'name' => ['like','%think%']]) //(id is in 1~3 or id>=1) and the name is similar to think->limit(10) ->select(); //Quick query$result = Db::table('think_inno')->where('id&num','>',1)->select(); id&numexpressand;id&numexpressor; //About viewUse the query results as a virtual table;TPUse it directly inDb::viewTo use the view $result = Db::view('think_inno','id,name')......; //think-inno is the table name, id and name are the fields to be checked//Use query object$query = new \think\db\Query;$query->table('think_inno')->where('name','like','think')->where('id','>=','3')->limit(10); $result = Db::select($query); print_r($result); //Get a certain value of a row in a column$name = Db::table('think_inno')->where('id',10)->value('name'); print_r($name); //Get the value of the name field with id 10//Get a column column$name = Db::table('think_inno')->where('status',1)->column('name'); //Take out all values corresponding to name column with status of 1//Get a certain line of find//Get the dataset of id key name$name = Db::table('think_inno')->where('num',0)->column('*','id'); print_r($name); //Aggregate query count, max, min, avg, sum$count = Db::table('think_inno')->where('num',0)->count();//Get the corresponding data volume with num 0$count = Db::table('think_inno')->where('num',2)->max('id');//Get the maximum id with num of 2
For more information about thinkPHP, please visit the special topic of this site:ThinkPHP Introduction Tutorial》、《Summary of the operation skills of thinkPHP templates》、《Summary of common methods of ThinkPHP》、《Codeigniter Introductory Tutorial》、《Advanced tutorial on CI (CodeIgniter) framework》、《Zend FrameWork framework tutorial"and"PHP template technical summary》。
I hope that the description in this article will be helpful to everyone's PHP programming based on the ThinkPHP framework.