如何在Windows和Linux中获取我在MySQL中运行的最后一次查询?
我正在使用PHP和CodeIgniter。在my_model.php
中,我有:
$query1 = ( ...something... );
$query2 = ( ...something... );
$variables = ( .... something .... );
$this->db->query(" $query1 ... $variables .. $query2", array( $variables, ... ));
我需要在上面的代码片段之后执行的最后一个查询。
谁能告诉我怎样才能得到我的最后一个查询?
发布于 2011-06-30 22:39:11
使用:
$this->db->last_query();
Returns the last query that was run (the query string, not the result). Example:
$str = $this->db->last_query();
// Produces: SELECT * FROM sometable....
取自query helper functions手册中的示例
发布于 2011-06-30 22:42:23
在CodeIgniter中有一个辅助函数$this->db->last_query();
。
这将返回上一次查询的字符串。
但我认为你可能会问如何获得结果,在这种情况下,你会这样做:
$query1 = ( ...something... );
$query2 = ( ...something... );
$variables = ( .... something .... );
$query = $this->db->query(" $query1 ... $variables .. $query2", array( $variables, ... ));
foreach ($query->result() as $row) {
//code goes here
}
有关更多信息,请查看CI's examples。
发布于 2016-10-25 15:56:33
在config/database.php中,必须设置配置数组:'save_queries‘=> TRUE,如果它是false,则不使用last_query()函数。
https://stackoverflow.com/questions/6536431
复制相似问题