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.

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 "


SELECT * FROM `student`

PHP mysqli info() Function

 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 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