这是在codeigniter中打印上次执行的查询的代码
print_r($this->db->last_query());
就像在PHP中打印上次执行的查询的代码是什么?
答案 0 :(得分:1)
您可以执行以下操作来获取上次执行的查询:
$mysql_last_query = ""; //this var contains the last mysql query function query($sql, $args) { #sintax: query("query", "arg1", "arg2", "argn"); EXAMPLE: query("select * from %s", $_GET["table"]); global $mysql_last_query; $args = func_get_args(); if(($num = func_num_args()) > 1) $sql = call_user_func_array("sprintf", $args); $mysql_last_query = $sql; return mysql_query($sql); } function select($table, $what = "*", $where = "", $limit = ""){ #this function is a "shortcut" for mysql select EXAMPLE: select("blah"); //SELECT * FROM blah and so on return mysql_query("SELECT ".$what." FROM ".$table.($where == "" ? "":(" WHERE ".$where)).($limit == "" ? "":(" LIMIT ".$limit))); }
希望有所帮助
答案 1 :(得分:1)
这是一个看似常见的问题。预期的方式似乎取决于日志记录: How to show the last queries executed on MySQL?