How to echo last executed query in PHP Codeigniter?

Today, We want to share with you codeigniter echo last query.In this post we will show you get last row id in codeigniter, hear for codeigniter get next auto increment id we will give you demo and example for implement.In this post, we will learn about print last query in codeigniter with an example.

how to get last inserted record in codeigniter?

codeigniter print last query - PHP
codeigniter print last query – PHP

This is a easy way to use $this->db->last_query() CI function to see SQL statements of last executed query in php codeigniter project.

Read Also:  Update Query In Codeigniter Example Tutorial

The CI query execution happens on all get methods such as a bellow code

$this->db->get('your_db_table_name');
$this->db->get_where('db_table_name',$array);

While last_query data contains the last query which was execute

$this->db->last_query();

Here is a simple CI controller code and also results for last query run:

Example:

public function getShopData()
{
    $sql_qq_str = $this->db->get("shop_information");
  
  	//get last executed sql query in codeigniter 3 Application
    $results = $this->db->last_query();
   
    echo "<pre>";
    dd($results);
}

Results

SELECT * FROM `shop_information`

I hope you get an idea about codeigniter insert query.
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.