Home > Article > Backend Development > php mysql coherent operation
The content shared with you in this article is the coherent operation of php mysql, which has a certain reference value. Friends in need can refer to it
<?php namespace app\index\controller; use think\Db; class User { public function index() { // 一般的where方法进行字符串参数传入查询 // dump(Db::name('user') // ->where('id=1 and name="wangjialin"') // ->find()); // 参数为数组 $map = [ // 'id'=> 2, // 'name' => 'zhangsan', // 'age' => ['>' , 10 ], // 'name' => ['like' , '%zhang%'], 'age' => ['between' , '14,18'] ]; // dump(Db::name('user')->where($map)->select()); // field order limit // dump(Db::name('user') // ->field('id , name as username, age') // ->select()); // dump(Db::name('user') // ->field(['id' , 'name as username' , 'age' , 'sex']) // ->order('id desc') // ->limit(1) // ->select()); // group having // dump(Db::name('user') // ->field(['sum(age) as all_age']) // ->group('password') // ->having('all_age > 50') // ->select()); // 聚合操作count avg sum min max dump(Db::name('user')->count()); dump(Db::name('user')->sum('age')); dump(Db::name('user')->avg('age')); // 获取最近的执行的sql语句 dump(Db::name('user')->getLastSql()); } }
Related recommendations:
PHP Methods to connect to mysql-mysqli and PDO
The above is the detailed content of php mysql coherent operation. For more information, please follow other related articles on the PHP Chinese website!