Common method for Yii to debug SQL, yii to debug SQL _PHP tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.