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

$this->db->last_query();

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

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

print last query in laravel

DB::enableQueryLog();

dd(DB::getQueryLog());

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

Example

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

How To Get Last Query In PHP Codeigniter?

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

public function student()
{
    $this->db->select('*'); 
    $query = $this->db->get("student");
    $student = $this->db->last_query();
    echo "<pre>";
    print_r($student);
}

results

SELECT * FROM `student`

PHP mysqli info() Function

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

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

$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 get last Eloquent print query

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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