在执行查询之前,如何从 Laravel 的查询构建器中获取原始查询字符串? [英] How can I get the raw query string from Laravel's query builder BEFORE executing the query?
本文介绍了在执行查询之前,如何从 Laravel 的查询构建器中获取原始查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个由几个条件创建的复杂查询,我想从即将执行的构建器对象中获取最终的 SQL 查询.我可以这样做吗?
I have a complex query created by a few conditions, and I would like to get the final SQL query from the builder object is about to execute. Can I do that?
推荐答案
你可以搞定:
$query = DB::table('brands')
->join('products','a','=','c')
->whereNull('whatever');
echo $query->toSql();
但是 Laravel 不会在查询中显示参数,因为它们是在准备好查询之后绑定的.
But Laravel will not show you parameters in your query, because they are bound after preparation of the query.
所以你也可以这样做:
print_r( $query->getBindings() );
这篇关于在执行查询之前,如何从 Laravel 的查询构建器中获取原始查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文