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
上一篇:使用crypto模块实现md5加密功能(解决中文加密前后端不一致的问题)


下一篇:What is difference between 'data:' and 'data()' in Vue.js?