想在在 CodeIgniter 中输出使用 Activerecord 构建的 SQL 语句,可能大家会想到好像 CI 没有提供这样的方法,那句直接去源代码里找找看吧。
果然,在 DB_active_rec.php 找到了 _compile_select(),是个私有的方法,不过大家可以直接使用,用法如下:
$this->db->select('id, name'); $this->db->where(“id>3”);
$this->db->from("users"); die($this->db->_compile_select());
输出如下:
SELECT id, name FROM users WHERE id>3
没有评论:
发表评论