Yii is a common method for SQL debugging. yii is used to debug SQL. Yii is a common method for SQL debugging. yii is mainly used to debug sqlYii SQL by the following methods: 1. built-in system debugging: first, index. php debug mode: removethefollowinglineswhen Yii
Yii has the following methods to debug SQL:
1. built-in system debugging:
First, enable the index. php debugging mode:
// remove the following lines when in production mode defined('YII_DEBUG') or define('YII_DEBUG',true); // specify how many levels of call stack should be shown in each log message defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); //app use time //defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME',microtime(true));
Main. php page:
'Errorhandler' => array (// use 'site/error' action to display errors 'erroraction' => 'site/error ',), 'log' => array ('class' => 'clogrouter', 'Routes '=> array ('class' => 'cfilelogroute ', 'levels' => 'Error, warning',), // The page log array ('class' => 'cweblogroute ', 'levels' => 'track ', // trace 'categories '=> 'system. db. * '// only displays information about the database, including database connection and database execution statements ),),),
The greater the number of YII_TRACE_LEVEL, the clearer the information.
II. use debugging tools for debugging:
Yii-debug-toolbar decompress the package, put it in extensions, and add it to the configuration file main. php.
'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute', 'ipFilters'=>array('127.0.0.1','192.168.1.215'), ), ), ),
If it does not appear, add two attributes to the database under 'Components,
'enableProfiling'=>true, 'enableParamLogging'=>true,
If there are plug-ins of other debugging tools, conflicts may occur, resulting in SQL statements not coming out. just note the code.
(Urgent) convert the result array queried by yii SQL to AR mode
In addition to cactivedataprovider, you can also use CArrayDataProvider
I will give you an example:
Controller:
$ Rawdata = Yii: app ()-> db-> createCommand ('select * from {post} where id <100 ')-> queryAll ();
$ Data = new CArrayDataProvider ($ rawdata, array (
'Id' => 'user ',
'Sort '=> array (
'Bubuckets' => array (
'Id', 'title', 'content'
),
),
'Pagination' => array (
'Pagesize' => 10,
),
));
$ This-> render ('gridview _ array', array ('dataprovider' => $ data ));
In the view:
$ This-> widget ('zii. widgets. grid. CGridView ', array (
'Id' => 'somegri ',
'Dataprovider' => $ dataProvider,
'Columns '=> array (
'Id ',
'Title ',
'Content ',
),
));
So OK ~
How to debug SQL functions
You just need to experiment one by one to see which result is returned. This self-explanatory language does not have any so-called debugging methods. One command is done. how do you think it is debugging?
Yii has the following methods to debug SQL: 1. debug the system: first, enable the debug mode for index. php: // remove the following lines when...