或者说,同事. 需要帮她打印出来sql 调试输出到页面sql

在这里,我们使用插件或一个的方式来启动配置文件wordpress的debug

在插件文件夹 wordpress/wp-content/plugins/ 新建一个文件叫bt_debug_sql.php

<?php
/*
Plugin Name:    Bt Debug Sql.
Plugin URI:     http://www.btroot.com
Description:    Show the sql at the frontpage.
Author:         rainysia
Version:        1.0
Author URI:     http://www.btroot.org
 */ /**
 * Show debug Sql.
 *
 * @return void
 */
add_action('init', 'bt_debug_sql'); function bt_debug_sql() {
    if (!defined('SAVEQUERIES')) {
        define('SAVEQUERIES', true);
    }
    if (has_action('wp_footer')) {
        add_action('wp_footer', 'snx_show_sql');
    }
}
// show sql
function snx_show_sql(){
    if (isset($_GET['debug']) && $_GET['debug'] == true) {
        global $wpdb;
        //echo '<pre>'; 
        //print_r ($wpdb->queries);
        $all_debug_queries = $wpdb->queries;
        echo "<table>";
        if (isset($all_debug_queries) && count($all_debug_queries) > 0) {
            $total_time_cost = 0;
            $large_time_cost = 0;
            $large_sql_query = '';
            $large_sql_num = 0;
            $debug_file = false;
            if (isset($_GET['debug_file']) && $_GET['debug_file'] == true) {
                $debug_file = true;
            }
            echo '<tr style="font-weight:bold;"><td>Num</td><td>Times</td><td>SQL</td>';
            echo $debug_file ? '<td>Include files</td><tr>' : '';
            foreach ($all_debug_queries as $k => $v) {
                // $v[0] is sql, $v[1] is time, $v[2] is relative file.
                $total_time_cost += $v[1];
                if ($large_time_cost <= $v[1]) {
                    $large_time_cost = $v[1];
                    $large_sql_query = $v[0];
                    $large_sql_num = $k + 1;
                }
                if (($k + 1) % 2 == 1) {
                    echo '<tr style="background-color:#8F9196;color:rgb(202, 227, 253);"><td style="font-weight:bold;text-align:center;">'.($k + 1).'</td>';
                } else {
                    echo '<tr><td style="font-weight:bold;text-align:center;">'.($k + 1).'</td>';
                }
                echo '<td style="text-align:left;">'.sprintf("%.10f", $v[1]).'</td>';
                echo '<td style="padding-left:6px;text-align:left;">'.$v[0].'</td>';
                echo $debug_file ? '<td style="text-align:left;">'.$v[2].'</td>' : '';
                echo '</tr>';
            }
        }
        echo '<div style="text-align:left;">';
        echo '<div style="widht:100%;height:3px;margin:10px 0;background:rgba(56, 83, 129, 0.85)!important; -moz-box-shadow:0px 0px 1px #c3c3c3; -webkit-box-shadow:0px 0px 1px #c3c3c3; -box-shadow:0px 0px 1px #c3c3c3;"></div>';
        echo '<div>The whole sql queries cost:<span style="color:red;"> '.$total_time_cost.'s</span></div>';
        echo 'The large sql is No.<span style="color:red;">'.$large_sql_num.'</span>  cost: <span style="color:red;">'.$large_time_cost.'s</span><br />  <span style="color:rgb(194, 76, 95);background-color:rgb(208, 210, 218);">'.$large_sql_query.'</span><br />';
        echo '<div style="widht:90%;height:3px;margin:10px 0px;background:rgba(128, 143, 158, 0.85)!important; -moz-box-shadow:0px 0px 1px #c3c3c3; -webkit-box-shadow:0px 0px 1px #c3c3c3; -box-shadow:0px 0px 1px #c3c3c3;"></div>';
        echo "</table>";
        echo '</div>';
    }
}

这里的作用仅仅是为了让wordpress的SAVEQUERIES 静态变量设为true, 所以你也能够不这样, 直接在wp-config.php 配置文件中面加一句

define('SAVEQUERIES', true);

效果是一样.

接着在/wp-content/theme/你的主题/footer.php 最后一个</div> 前加上以下的代码来调用一次wp_footer();保存就可以.

<?php wp_footer();?>

保存后就能够了. 然后去启用插件, 使用的时候, 在当前页面的url后跟?debug=true 能够开启debug sql模式, 加debug_file=true会显示include的关联文件.

http://test.com/solutions/vwideformat/test/?debug=1 和

http://test.com/solutions/vwideformat/test/?

debug=1&debug_file=1

效果例如以下

版权声明:本文博客原创文章。博客,未经同意,不得转载。

[改变自己wordpress.2]给wordpress加上简单debug sql调试.的更多相关文章

  1. [改变自己wordpress.2]至wordpress再加上简单的debug sql调试.

    或者说,同事. 需要帮助她打印出来sql 调试输出到页面sql 在这里,我们使用插件或一个的方式来启动配置文件wordpress的debug 在插件文件夹 wordpress/wp-content/p ...

  2. [20190328]简单探究sql语句相关mutexes.txt

    [20190328]简单探究sql语句相关mutexes.txt --//摘要:http://www.askmaclean.com/archives/understanding-oracle-mute ...

  3. 最简单删除SQL Server中所有数据的方法

     最简单删除SQL Server中所有数据的方法 编写人:CC阿爸 2014-3-14 其实删除数据库中数据的方法并不复杂,为什么我还要多此一举呢,一是我这里介绍的是删除数据库的所有数据,因为数据之间 ...

  4. 实验吧_简单的sql注入_1、2、3

    简单的sql注入1 看着这个简单的界面,一时间没有特别好的思路,先输入一个1',发生了报错 初步猜测这是一个字符型的注入,他将我们输入的语句直接当成sql语句执行了,按题目的意思后面肯定过滤了很多注入 ...

  5. 【实验吧】CTF_Web_简单的SQL注入之3

    实验吧第二题 who are you? 很有意思,过两天好好分析写一下.简单的SQL注入之3也很有意思,适合做手工练习,详细分析见下. http://ctf5.shiyanbar.com/web/in ...

  6. 【实验吧】CTF_Web_简单的SQL注入之1

    题目链接:http://ctf5.shiyanbar.com/423/web/ 简单的SQL注入之1,比2,3都简单一些.利用2 的查询语句也可以实现:1'/**/union/**/select/** ...

  7. 四种简单的sql语句(增删改查语句)

    四种简单的sql语句(增删改查语句) 一.插入语句 insert into [table] ([column],[column],[column]) values(?,?,?) 二.删除语句 dele ...

  8. 简单了解SQL(结构化查询语言)

    简单了解SQL(结构化查询语言) 年10月,美国国家标准学会对SQL进行规范后,以此作为关系式数据库管理系统的标准语言(ANSI X3. 135-1986),1987年得到国际标准组织的支持下成为国际 ...

  9. tp5 r3 一个简单的SQL语句调试实例

    tp5 r3 一个简单的SQL语句调试实例先看效果核心代码 public function index() { if (IS_AJAX && session("uid&quo ...

随机推荐

  1. hdu2844(多重背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2844 题意:一位同学想要买手表,他有n种硬币,每种硬币已知有num[i]个.已知手表的价钱最多m元,问 ...

  2. 依据二度人脉推荐好友sql

    friend表结构 DROP TABLE IF EXISTS FRIEND; create table friend(     uid        bigint not null comment ' ...

  3. iOS_25彩票_幸运转盘

    终于效果图: 各个view的关系图: 背景圆盘(须要扣图处理)LuckyBaseBackground.png 盖在背景圆盘上面的转盘 LuckyRotateWheel.png watermark/2/ ...

  4. A Game of Thrones(0) - PROLOGUE

    "We should start back", Gared urged as the woods began to grow dark around them. "The ...

  5. java它们的定义ArrayList序列, 大神跳跃

    一个list有两种类型的对象,今天有需求必须责令不同的约会对象,这里是代码 /** *@author xh1991101@163.com */ List<Message> messages ...

  6. 状态压缩dp(hdu2167,poj2411)

    hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...

  7. Array of Objects

    You should be comfortable with the content in the modules up to and including the module "Array ...

  8. winzip15.0许可证

    username:Juzhaofeng 授权码:MPZRP-Y7LWW-K1DKG-FM92E-2C5F5-ZEKFF

  9. Hadoop认知--在不同的阶段

    入门阶段 出于兴趣,及工作中的简单有用,大约经过1个月的时间,完毕了对Hadoop的基本认知. 在这个月中我干了例如以下几件事 1.大体看了<Hadoop权威指南>.把里面的代码手工码了一 ...

  10. windows任务设置定时

    windows 的Schedule Task .创建一个配置 1.点击"开始" 2.点击"控制面板" 3.双击"任务计划程序" 4.双击&q ...