【问题标题】:Getting CodeIgniter Active Record's current SQL code获取 CodeIgniter Active Record 的当前 SQL 代码
【发布时间】:2011-04-07 23:46:23
【问题描述】:

例如,我想转换这个;

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

到这个;

'SELECT * FROM table'

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

【问题讨论】:

    标签: php activerecord codeigniter


    【解决方案1】:

    您也可以使用$this->db->get_compiled_select()get_compiled_select()last_query() 之间的区别在于 get_compiled_select() 给出了即使您不针对数据库运行查询也会生成的查询字符串。

    【讨论】:

    • 我刚刚意识到,如果你使用_compile_select(),你必须在执行查询后使用$this->db->_reset_select();。如果不这样做,CodeIgniter 将不会清除查询,并且以后的所有查询都将不起作用。
    • _compile_select() 不再工作,因为他们在最新的 CI2 Github 存储库中保护了该功能。我多次使用此功能,现在我被卡住了。也许有解决办法?
    • 搜索CI commit history后,才看到有一个新的public方法; get_compiled_select()codeigniter.com/nightly_user_guide/database/…
    • 致命错误:调用未定义的方法 CI_DB_mysql_driver::get_compiled_select()
    【解决方案2】:

    试试

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

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

    【讨论】:

      猜你喜欢
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      相关资源
      最近更新 更多