Codeigniter:does $ this-> db-> last_query();执行查询? [英] Codeigniter: does $this->db->last_query(); execute a query?

查看:480
本文介绍了Codeigniter:does $ this-> db-> last_query();执行查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查询执行是否发生在以下codeigniter活动记录语句的 get_where()子句中?

Does query execution happen at the get_where() clause of the following codeigniter active record statement?

$this->db->select('*');
    $q = $this->db->get_where('Contacts', array('id' => $contact_id));

    $sql = $this->db->last_query();

或者一旦调用 result_array()

并且 $ this-> db-> last_query();

推荐答案

查询执行发生在所有get方法,例如

The query execution happens on all get methods like

$this->db->get('table_name');
$this->db->get_where('table_name',$array);

last_query包含运行的最后一个查询

While last_query contains the last query which was run

$this->db->last_query();

如果你想获得查询字符串而不执行,你必须这样做。
转到系统/数据库/ DB_active_rec.php从这些函数中删除public或protected关键字

If you want to get query string without execution you will have to do this. Go to system/database/DB_active_rec.php Remove public or protected keyword from these functions

public function _compile_select($select_override = FALSE)
public function _reset_select()

现在你可以编写查询in a variable

Now you can write query and get it in a variable

$this->db->select('trans_id');
$this->db->from('myTable');
$this->db->where('code','B');
$subQuery = $this->db->_compile_select();

现在重置查询,如果要写另一个查询对象将被清除。

Now reset query so if you want to write another query object will be cleared.

$this->db->_reset_select();

事情已经完成了。干杯!!!
注意:使用这种方式时,您必须使用

And the thing is done. Cheers!!! Note : While using this way you must use

$this->db->from('myTable')

而不是

$this->db->get('myTable')

运行查询。

看看这个例子

这篇关于Codeigniter:does $ this-> db-> last_query();执行查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆