Home  >  Article  >  Backend Development  >  How to implement the Yii framework to output and execute sql statements on the page and debug them

How to implement the Yii framework to output and execute sql statements on the page and debug them

不言
不言Original
2018-06-15 10:34:281976browse

This article mainly introduces the implementation method of Yii framework to output and execute sql statements on the page to facilitate debugging. It involves the use of yiidebugtb, which is a more practical technique. Friends in need can refer to the following

Examples of this article The Yii framework implements the method of outputting and executing sql statements on the page to facilitate debugging. Share it with everyone for your reference. The specific analysis is as follows:

We use: yiidebugtb for debugging (because the interface is more beautiful and does not affect other elements of the interface).

1. Download yiidebugtb and put it into the application.extensions.yiidebugtb directory

2. Modify main.php and add the following code:

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
 array(
     'class'=>'CFileLogRoute',
     'levels'=>'error, warning,trace',
 ),
 // 以下是新加
 array( // configuration for the toolbar
     'class'=>'XWebDebugRouter',
     'config'=>'alignLeft, opaque, runInDebug, fixedPos, collapsed, yamlStyle',
     'levels'=>'error, warning, trace, profile, info',
     //'categories' => 'system.db.*',
     'allowedIPs'=>array('127.0.0.1','::1','192\.168\.1[0-5]\.[0-9]{3}','如果程序在外网需要填入你的公网的ip'),
   ),
 
    ),
)

3.db link Make the following modifications in the configuration:

'db'=>array(
    'connectionString'=>'mysql:host=*.*.*.*;dbname=test',
    'emulatePrepare'=>true,   // 加入
    'enableParamLogging' => true, // 加入 
    'username'=>'-----',
    'password'=>'---',
    'charset'=>'utf8',
    'schemaCachingDuration'=>'0',
    'autoConnect'=>false,
),

4. The running effect is shown in the figure below:

The above is the entire content of this article, I hope it will be helpful to everyone's learning For help, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

How to use PHPExcel to export Excel files in the Yii2 framework

The above is the detailed content of How to implement the Yii framework to output and execute sql statements on the page and debug them. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn