或者说,同事. 需要帮她打印出来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. java -D參数简化增加多个jar【简化设置classpath】

    1.-D<name>=<value> set a system property  设置系统属性. java命令引入jar时能够-cp參数,但时-cp不能用通配符(多个jar时 ...

  2. OpenLayers学习笔记4——使用jQuery UI实现測量对话框

    OpenLayers学习最好的方式就是跟着其自带的演示样例进行学习,另外对web前端的开发设计要了解,慢慢积累,这样在一般的小项目中应该是足够用了. 本篇參照量測demo实现对话框形式的量測,抛砖引玉 ...

  3. 基于Redis Sentinel的Redis集群(主从Sharding)高可用方案(转)

    本文主要介绍一种通过Jedis&Sentinel实现Redis集群高可用方案,该方案需要使用Jedis2.2.2及以上版本(强制),Redis2.8及以上版本(可选,Sentinel最早出现在 ...

  4. Learning Cocos2d-x for WP8(6)——场景切换和场景过渡效果

    原文:Learning Cocos2d-x for WP8(6)--场景切换和场景过渡效果 C#(wp7)兄弟篇 Learning Cocos2d-x for XNA(6)——场景切换和场景过渡效果 ...

  5. registerWithTouchDispatcher()函数的使用

    registerWithTouchDispatcher()函数的使用 registerWithTouchDispatcher()函数主要用于注册Touch事件. 当我们使用this->setTo ...

  6. Windows Phone开发(11):常用控件(下)

    原文:Windows Phone开发(11):常用控件(下) WP控件大部分都可以从Silverlight中继承过来,这里我也只能拿一部分作演示,对于其它控件如何使用,可以参考SDK相关说明以及Sil ...

  7. 基于j2ee的程序代写MVC架构

    人力资源管理系统 完成系统静态页面设计,页面数量不少于10个,页面需用CSS进行美化,并为需要验证的信息利用JavaScript提供客户端验证.要求至少包含部门信息及部门内员工信息的添加.修改.删除和 ...

  8. Android从无知到有知——NO.7

    的ip拨号器在监听外拨电话时用的是系统提供的广播事件.而有些时候我们须要自己设定广播事件来满足特定的须要. Ok,今天整一下自己定义广播事件,我们用一个状态监測模块向一个3G模块发送报警信息来实现这一 ...

  9. 【转】QT样式表 (QStyleSheet)

    作者:刘旭晖 Raymond 转载请注明出处Email:colorant@163.comBLOG:http://blog.csdn.net/colorant/ 除了子类化Style类,使用QT样式表( ...

  10. 解决win10 iot VS编程出现的无法引用错误

    使用NuGet安装 Microsoft.NETCore 5.0 安装 Microsoft.NETCore