Table of Contents
Inside this article we will see the concept of printing executed SQL query in wordpress. In several cases we want to print the executed sql query, print result set data of wordpress.
If you are looking for an article i.e How to print the executed sql query in wordpress then you are at right place to get the things. This article contains classfied information which gives you the prefect idea to learn and run your queries.
Premium Courses Running Out, Grab Now!
Master the Coding Skills to Become an Expert in Web Development. A lifetime of knowledge at your fingertips.
Enroll in your favourite web development courses risk-free at $4 only.
Learn More –
- Best Free WordPress Plugins For Programming Blog Website
- Complete Basics Overview of WordPress Widget
- Create a Basic Widget Plugin in WordPress ?
- How to Download with Countdown Timer in WordPress
Let’s get started.
What is WordPress Core Database Class?
WordPress manages almost 99% data via it’s database. Database is one of the major part of wordpress which when lost or destroyed then site will be crashed. There are 10000+ of plugins available free at wordpress repository to get any type of data from site database.
WordPress database object comes into play. It is global which can use anywhere by calling it’s methods.
To perform any database operations, WordPress provides a class called wpdb which is present in the directory at core libraries wordpress folder /wp-includes and file is /wp-includes/wp-db.php
The class “wpdb” abstracts the wordpress database functions. Most of the WordPress functions directly or indirectly use wpdb class. WordPress class wpdb based on the concept ezSQL class.
We can create an object of this wpdb class and perform all database operations but wordpress auto creates an object of this class while wordpress loads.
Print Executed SQL in WordPress
To print sql queries in wordpress we use $wpdb object. The
$wpdb object has some properties for this.
There are few easy steps to do so –
SAVEQUERIESand printing all the queries in footer
$wpdb->last_queryto print just the latest query executed, this is useful for debugging functions.
- Using a plugin like Query Monitor.
We need to add this in wp-config.php
Using $wpdb properties to debug queries
global $wpdb; // Print last SQL query string echo $wpdb->last_query; // Print last SQL query result echo $wpdb->last_result; // Print last SQL query Error echo $wpdb->last_error;
We hope this article helped you to learn How To Print The Executed SQL Query in WordPress Tutorial in a very detailed way.