Home » How To Print Last Query In PHP?

How To Print Last Query In PHP?

Today, We want to share with you How To Print Last Query In PHP?.In this post we will show you codeigniter print query before executing, hear for mysql last query core php with mysqli last query we will give you demo and example for implement.In this post, we will learn about Print Last Query In Laravel Eloquent – Examples with an example.

Read Also:  Ajax Login System with jQuery PHP and MySQLi

Printing Last Executed Mysql Query In PHP

Get last executed query in MySQL with PHP/CodeIgniter

using CodeIgniter


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

// Produces: SELECT * FROM students.... 

print last query in laravel



print last query in laravel

DB::enableQueryLog(); // Enable query log

// Your laravel Eloquent query executed by using get()

dd(DB::getQueryLog()); // Show results of log

Echo Last Executed Query In Laravel 5

$query = DB::getQueryLog();
$lastmyQuery = end($query);


$students= DB::select('select * from students where 9');
$query = DB::getQueryLog();
$lastmyQuery = end($query);

How To Get Last Query In PHP Codeigniter?

Here is a simple Codeigniter controller PHP code and also results for last query:

public function student()
    $query = $this->db->get("student");
    $student = $this->db->last_query();
    echo "<pre>";


SELECT * FROM `student`

PHP mysqli info() Function

$mysqli = new mysqli("localhost","root","DF9856FDG#$df54","pakainfo");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;

$mysqli -> query("CREATE TABLE students LIKE stud");
$mysqli -> query("INSERT INTO students SELECT * FROM stud ORDER BY LastName");

echo $mysqli -> info;

$mysqli -> close();

I hope you get an idea about Last Query In PHP.
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:  Laravel All Where eloquent methods with Examples

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  How to Make a Redirect to page in PHP?
  2. Read Also:  PHP Star Triangle Program printing Source Code
  3. Read Also:  Get minimum key value of array in PHP
  4. Read Also:  Laravel updateOrCreate, firstOrNew, firstOr and firstOrCreate Methods
  5. Read Also:  laravel Add cascade on delete (ON DELETE CASCADE)
  6. Read Also:  laravel middleware check custom header for REST API
  7. Read Also:  how to create plugin in wordpress with example
  8. Read Also:  Laravel 6 Update Increment column
  9. Read Also:  Nested Queries Subqueries in SQL Example
  10. Read Also:  Laravel 6 LIKE query example using Eloquent WHERE clause

Leave a Comment

Your email address will not be published. Required fields are marked *