Output current page in WordPress SQL statement method

https://www.jb51.net/cms/145455.html

 

1. Code embodiment
first step, open wp-config.php, add
 

Copy the code

code show as below:

define('SAVEQUERIES', true);


WordPress will open SAVEQUERIES the sql query execution to save the current page into an array, the array holds the per-query statement, call the function as well as the execution time of the query. Print this array as long as the current page will be able to understand all sql queries, so ...
the second step, the print array, the following code into the </ body> front footer.php
 

Copy the code

code show as below:


<?php
if (current_user_can('administrator')){
global $wpdb;
echo "<pre>";
print_r($wpdb->queries);
echo "</pre>";
}
?>


Specifically refer to the official documentation: http: //codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis
For security reasons, this code is limited only administrators can see
2. Install the plug
has a plug-in can be the perfect completion of the above function, and display format sql statement with clarity, look more comfortable, not to modify the wp-config.php, used up can be deleted, so convenient.
Plug Name: Debug Queries 
Download: http: //wordpress.org/plugins/debug-queries/
download the plug-in, you can see all the Sql queries, of course, also need administrator privileges at the front desk after activation.

Guess you like

Origin blog.csdn.net/james_laughing/article/details/92777809