ItSolutionStuff.com

Codeigniter Get Last Executed Query Log Example

By Hardik Savani • November 5, 2023
PHP MySql Codeigniter

In this post, i would like to show you how to get last executed query in php codeigniter 3 website using last_query() function. you can print last executed sql query like select query, create query, update query, delete query etc.

Whenever you are working on big amount of project and you write long query code using sub query, order by, group by etc. but we write sql query using codeigniter query builder so it might be easy for us. But if you need to print last executed query then you can do it using last_query() function.

Here, i will show you very simple example, so you can get it quickly. We will get all items from database table using select query as bellow example.

Controller Code:

/**

* Get All Data from this method.

*

* @return Response

*/

public function index()

{

$data['data'] = $this->db->get("items")->result();

$executedQuery = $this->db->last_query();

print_r($executedQuery);

exit;

}

Output:

SELECT * FROM `items`

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Change Date Format in Codeigniter?

Read Now →

How to Get form Post Data in Controller Codeigniter?

Read Now →

How to Get All Tables List in Codeigniter?

Read Now →

Codeigniter Ajax Pagination using JQuery Example

Read Now →

Codeigniter Resize Image and Create Thumbnail Example

Read Now →

Codeigniter Drag and Drop Multiple Image Upload Example

Read Now →

How to Get Current Controller or Method Name in Codeigniter?

Read Now →

How to Implement Flash Messages in Codeigniter?

Read Now →

Codeigniter Image Upload with Validation Example

Read Now →

How to Get Last Record in Codeigniter?

Read Now →

Codeigniter Generate PDF from View using Dompdf Example

Read Now →

Codeigniter Select2 Ajax Autocomplete from Database Example

Read Now →

How to Get Current URL with Query String in Codeigniter?

Read Now →

How to Get Query Log in Laravel Eloquent?

Read Now →