How to Get Last Executed Query in Codeigniter?

Today, We want to share with you codeigniter get last query.In this post we will show you last query in ci, hear for code-igniter last insert id we will give you demo and example for implement.In this post, we will learn about Codeigniter Print Last Query – PHP with an example.

How to get last executed query in PHP Codeigniter?

Example 1:

public function demo_example_db()
{
    $query = $this->db->get("members");
  
    $str = $this->db->last_query();
   
    echo "<pre>";
    print_r($str);
    exit;
}

Results

SELECT * FROM `members`

PHP Codeigniter get last executed query example

using Controller Code:

/**
 * Get All Data from this method.
 *
 * @return Response
*/
public function index()
{
    $data['data'] = $this->db->get("members")->result();
    $executedQuery = $this->db->last_query();
    print_r($executedQuery);
    exit;
}

Results

SELECT * FROM `members`

I hope you get an idea about Get last executed query in MySQL with PHP/CodeIgniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.