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.
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.
Online Web Tutor invites you to try Skillshare free for 1 month! Learn CakePHP 4, Laravel APIs Development, CodeIgniter 4, Node Js, etc into a depth level. Master the Coding Skills to Become an Expert in Web Development. So, Search your favourite course and enroll now. Click here to join.