$data = Db::query('select * from tf_action');
$data = Db::query('select * from tf_action where id > ? and id < ?',[1,10]);
$sql = Db::getLastSql();
Queries with query.
Delete, add, modify, use Execute.
$data = Db::table('tf_action')->select();
The full name of the table is used here.
$data = Db::name('action')->select();
Here is the name of the table with the prefix removed.
$data = db('action')->select();
Helper function, the effect is similar to Db::name.
But it's not exactly the same.
$data = db('action')->where('id','>',1)->where('id','<',9)->select();
Multi-criteria queries.
$data = db('action')->where('id','>',20)->whereOr('id','<',9)->select();
or query.
If the middle condition is empty, it means =.
$where = new Where();$where['name'] = ['like','%户%'];$where['id'] = ['>',1];$data = db('action')->where($where)->select();
$where[] = ['name','like','%户%'];$where[] = ['id','>',1];$data = db('action')->where($where)->select();
Combine queries.
$where = new Where();$where['name'] = ['like','%户%'];$where['id'] = ['>',1];$data = db('action')->where($where)->limit(2,2)->order('id desc')->select();
Pagination sorting.
$where = new Where();$where['name'] = ['like','%户%'];$where['id'] = ['>',1];$data = db('action')->where($where)->limit(2,2)->order('id desc')->field('id,name')->select();
queries the specified field.
$where = new Where();$where['name'] = ['like','%户%'];$where['id'] = ['>',1];$data = db('action')->where($where)->limit(2,2)->order('id desc')->field('id aid,name')->select();
Alias.
$data = db('action')->where($where)->field('count(*) as count')->find();
Use System functions.
$data = db('action')->where("name like '%户%' AND id > 1")->select();
It is ok to write the string directly.
TP5 Database DB query operation