php - 使用 PHP/CodeIgniter 在 MySQL 中获取最后执行的查询

标签 php mysql codeigniter

如何在 Windows 和 Linux 中获取我在 MySQL 中运行的最后一个查询?

我正在使用 PHP 和 CodeIgniter。在 my_model.php 中,我有:

$query1 = ( ...something... );
$query2 = ( ...something... );
$variables = ( .... something .... );
$this->db->query(" $query1 ... $variables .. $query2", array( $variables, ... ));

我需要在上面的代码片段之后执行的最后一个查询。

谁能告诉我怎样才能得到我的最后一个查询?

最佳答案

使用:

$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 上的手册

关于php - 使用 PHP/CodeIgniter 在 MySQL 中获取最后执行的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6536431/

相关文章:

php - 所有站点交互均通过单个页面进行

php - 将用户重定向到登录页面但仍在使用他们的搜索查询

Mysql在存储过程中临时禁用auto_increment列

MySQL 与 MariaDB : add row number

mysql - PHP MySQL 选择 2 列,其中 1 列

php - 如何在 Codeigniter 中将所有上传图像的文件名添加到数据库中?

php - 如何获取一张表中的选定元素?

php - 文件获取内容(): php_network_getaddresses: getaddrinfo failed

php - 无法在 phpmyadmin 中打开某些表

php - 从 CodeIgniter 中的另一个表中获取用户名和用户 ID