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:  codeigniter last query (last query ci) Examples

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.

Read Also:  ci last query | last query ci | get last query codeigniter Example

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Update Query In Codeigniter Example Tutorial
  2. Read Also:  CodeIgniter Autocomplete Multiple input textbox with Database
  3. Read Also:  Access Control Allow Origin http set Headers
  4. Read Also:  How to set (Create), Access and Delete Cookies in codeigniter ?
  5. Read Also:  delete Query In Codeigniter Example Tutorial
  6. Read Also:  last query ci - codeigniter last query Example
  7. Read Also:  how to upload multiple separate images in codeigniter with database?
  8. Read Also:  select Query In Codeigniter Example Tutorial
  9. Read Also:  codeigniter Controller pass parameter route Function
  10. Read Also:  insert Query In Codeigniter Example Tutorial
CLOSEX