laravel的ORM转为原生sql

注:mysql测试成功,mongoDB测试失败
//将laravel的ORM转为原生sql $SubProfits为laravel的ORM对象
$SubProfits = model::where('id','<=',20)->where('display',1);
$bindings = $SubProfits->getBindings(); //获取参数,本例中为20和1
$sql = str_replace('?', '%s', $SubProfits->toSql());
$sql = sprintf($sql, ...$bindings); //... 为将数组循环转为字符串

...测试
$a = ['a',b];
print_r(...$a);//只输出a;
var_dump(...$a);//输出a,b
posted @ 2019-05-25 17:06  php、凯  阅读(3289)  评论(0编辑  收藏  举报