codeigniter print last query – PHP Examples

Today, We want to share with you codeigniter print last query – PHP.In this post we will show you codeigniter query, hear for join query in codeigniter we will give you demo and example for implement.In this post, we will learn about print last query in codeigniter with an example.

codeigniter print last query – PHP

There are the Following The simple About codeigniter print last query Full Information With Example and source code.

As I will cover this Post with live Working example to develop where condition in codeigniter, so the codeigniter delete query return value is used for this example is following below.

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

Codeigniter print last query : Codeigniter provides database class to deal with database. You can use simple $this->db->last_query(); to display or print last run MySQL query. This query prints the last executed sql statement by codeigniter. Here in this best Post I am gonna to make a one example to display print last query.

Example : codeigniter print last query

In PHP Based codeIgniter I can retrive the last executed MySQL Statements With One of the codeigniters Query Helper methods called last_query(), you can use this as display or run below Example

This CI function is incredibly very Imp for all the CI devlopers helpful while CI Source code debugging generated Queries by alkl the Active Rows.

  $this->db->last_query();

using $this->db->last_query();

Example – To print or display executed sql statement at last In Codeigniter

$query = $this->db->get("products");
echo $this->db->last_query();

In the above simple CI example I have used get method to pull the all the collumns data from products MySQL Database table. After execution it Will print the sql statement – “Select * from products”. So on the same way you can print any complex sql statement Like – Insert, Update, Delete, Joins, Union etc in Codeigniter.

How to get last executed query in PHP Codeigniter?

Example

Here is a simple codeigniter controller source code as well as also output for last query:

public function getDoctorsList()
{
    $query = $this->db->get("doctors");
  
    $str = $this->db->last_query();
   
    echo "
";
    print_r($str);
    exit;
}

Results


SELECT * FROM `doctors`

Codeigniter (CRUD) Select Insert Update Delete Query

  1. Update Query In Codeigniter
  2. Select Query In Codeigniter
  3. Insert Query In Codeigniter
  4. Delete Query In Codeigniter
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about print last sql query in codeignite Example with Demo.
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.

Leave a Comment