Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last executed query in MySQL with PHP/CodeIgniter

Tags:

How can I get last query I ran in MySQL in both Windows and Linux?

I am working with PHP and CodeIgniter. In my_model.php, I have:

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

I need the last query executed right after the code snippet above.

Can anyone tell me how can I get my last query?

like image 224
soredive Avatar asked Jun 30 '11 14:06

soredive


1 Answers

Use:

$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....  

example taken from the manual on query helper functions

like image 200
Damien Pirsy Avatar answered Sep 20 '22 18:09

Damien Pirsy