$sql->Where("open", 0)
->whereRaw("concat(`phone`,`email`,`username`) like '%".$data['search']."%'")
->where("id",">",50)
->where("id","<",100);
打印出sql语句:
orm直接调用toSql()方法,如:
$sql = UserModel::query()->where('role','2')->toSql();
dd($sql); //select * from User_table where role = '2'
查询最后执行的一条sql语句的方法:
DB::connection()->enableQueryLog();
$query = DB::table('test')->orderBy('id', 'desc')->get();//需要执行的SQL语句
echo '<pre>';
print_r(DB::getQueryLog());
执行结果为
Array
(
[0] => Array
(
[query] => select count(*) as aggregate from `sj_real` where `real_status` = ?
[bindings] => Array
(
[0] => 1
)
[time] => 225.01
)
[1] => Array
(
[query] => select * from `sj_real` where `real_status` = ? order by `real_id` desc limit 15 offset 0
[bindings] => Array
(
[0] => 1
)
[time] => 45
)
)