find() 查询
<?php namespace app\index\controller; use \think\Db; class Index { public function index() { return '正在学习中...'; } public function demo() { dump( Db::table('shop_name') ->field(['id','name','type']) ->where('id',16) ->find() //返回查询结果 ); } }
数组查询方式
<?php namespace app\index\controller; use \think\Db; class Index { public function index() { return '正在学习中...'; } public function demo() { dump( Db::table('shop_name') ->field(['id','name','type']) ->where([ 'price'=>['>', 15], ]) ->select() //返回查询结果 ); } } 闭包查询 <?php namespace app\index\controller; use \think\Db; class Index { public function index() { return '正在学习中...'; } public function demo() { dump( Db::table('shop_name') ->field(['id','name','price','type']) ->where(function ($query){ $query->where('price','>','15'); }) ->select() //返回查询结果 ); } 简化: <?php namespace app\index\controller; use \think\Db; class Index { public function index() { return '正在学习中...'; } public function demo() { dump( Db::select( function ($query){ $query->table('shop_name') ->field(['name','price','type']) ->where([ 'id'=> ['=',1] ]); } ) ); } }