codeigniter活动记录,生成,但不执行查询

Pet*_*ter 2 php activerecord codeigniter

我正在工作一个库,需要将sql查询作为字符串提供给它的工作.

我正在使用CodeIgniter和他们的数据库类的活动记录实现.

我知道我可以像这样回应SQL语句......但我只想生成这个查询,而不是执行它.

 echo $this->db->last_query();
Run Code Online (Sandbox Code Playgroud)

任何帮助实现这一点都会很棒!

Muh*_*eel 6

有一点hack你可以去system/DB_active_rec.php并删除protected keyword form _compile_select方法,现在

return $this->db->_compile_select();
Run Code Online (Sandbox Code Playgroud)

也用 $this->db->from('table');

而不是get()因为get将执行查询这是一个例子

function index(){
    $this->db->select('blah blah');
    $this->db->from('table');
    $string = $this->db->_compile_select();
    return $string;
}
Run Code Online (Sandbox Code Playgroud)


Phi*_*eon 5

取决于它是哪种类型的查询.insert和update包含允许您执行此操作的方法.

$this->db->set('foo', $bar);
$this->db->update_string('table'); // UPDATE table SET foo = "bar"
Run Code Online (Sandbox Code Playgroud)