Yii查看(输出)当前页面执行的sql语句
本文分享一下在Yii框架下查看当前页面执行的所有sql语句的方法,主要是通过配置相关文件来达到调试sql的目的,具体方法如下:
(1)修改 index.php 开启调试模式
在 index.php 文件内增加如下两行代码(如果不存在的话):
//开启调试模式 defined('YII_DEBUG') or define('YII_DEBUG',true); //设置日志记录级别,YII_TRACE_LEVEL的数字越大,信息越清楚 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
(2)修改配置文件 main.php
在config/main.php的 components - log - routes 下加入如下数组:
array( 'class'=>'CFileLogRoute',//文件记录日志的形式 'levels'=>'trace',//日志记录级别 'categories'=>'system.db.*',//只显示关于数据库信息,包括数据库连接,数据库执行语句 'logFile' => 'app_'.date('Y-m-d').'.log',//日志保存文件名 'logPath'=>'D:\phpStudy\WWW\phpernote\com\tmpfile\log_db',//日志保存路径 ),
ok,经过如上的设置,刷新页面,你就可以到 D:\phpStudy\WWW\phpernote\com\tmpfile\log_db 这个目录里面去查找生成的sql记录文件了。输出的日志格式如下:
[时间] - [级别] - [类别] - [内容]
2015/04/17 10:30:51 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `phpernote_article` ORDER BY id desc LIMIT 15
您可能感兴趣的文章
- mysql查看当前运行的sql语句
- PHP获取当前页面完整url地址函数,包括参数
- 如何查看数据库表的当前自增值
- 如何知道数据库中那些执行的SQL语句比较慢
- 如何使用zlib压缩输出内容以提高网页打开速度
- linux查看文件有多少行,linux wc命令详解
- 如何通过命令行查看memcache当前运行的状态
- js适时输出当前的时间

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
