get last executed query in PHP Codeigniter

get last executed query in PHP Codeigniter

get last executed query in PHP Codeigniter
get last executed query in PHP Codeigniter

howdy guys !! In this post , I will explain how to get last executed query in PHP Codeigniter 3 . I will help you to get last query executed in MySQL by using function  last_query()  of db class of codeigniter 3, Returns the last query that was run  not result.

last query executed in MySQL by using Codeigniter 3

last_query()  function is the inbuilt function of codeigniter 3.

Very simple to use

Use:

$this->db->last_query();

Returns the last query that was run (the query string, not the result). Example:
$str = $this->db->last_query();
echo $str;

// Produces: SELECT * FROM sometable.... 

For example lets start

 

public function check_query(){
    $query = $this->db->get("tbl_category");
    $str = $this->db->last_query();
    echo $str;
}

Output:

select * from tbl_category.

 

We hope you can learn something from this post. if you like this article

Sharing is Caring !!!

Written By

vijay1983

Leave a Reply