php 获取 CodeIgniter Active Record 的当前 SQL 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3638348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:31:09  来源:igfitidea点击:

Getting CodeIgniter Active Record's current SQL code

phpactiverecordcodeigniter

提问by WhoSayIn

for example, i want to convert this;

例如,我想转换这个;

$this->db->get('table');

to this;

对此;

'SELECT * FROM table'

is there any function for this? i searched on the user guide of CI but didnt find any solution.

有什么功能吗?我搜索了 CI 的用户指南,但没有找到任何解决方案。

回答by Sandy

You can also use $this->db->get_compiled_select(). The difference between get_compiled_select()and last_query()is that get_compiled_select()gives the query string generated even if you don't run the query against the database.

您也可以使用$this->db->get_compiled_select(). 之间的区别get_compiled_select(),并last_query()get_compiled_select()让即使你没有对数据库运行的查询生成的查询字符串。

回答by sitesbyjoe

Try

尝试

echo $this->db->last_query();

after you run your Active Record Query and it'll spit out the raw SQL it ran for you. I use it often.

在你运行你的 Active Record Query 之后,它会吐出它为你运行的原始 SQL。我经常使用它。