Heim  >  Artikel  >  Backend-Entwicklung  >  Yii调试SQL的常用方法,yii调试sql_PHP教程

Yii调试SQL的常用方法,yii调试sql_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:23:18779Durchsuche

Yii调试SQL的常用方法,yii调试sql

Yii调试SQL主要有以下方法:

一、系统自带调试:

首先index.php开启调试模式:

// 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页面:

'errorHandler'=>array( 
  // use 'site/error' action to display errors 
  'errorAction'=>'site/error', 
), 
'log'=>array( 
  'class'=>'CLogRouter', 
  'routes'=>array( 
    array( 
      'class'=>'CFileLogRoute', 
      'levels'=>'error, warning', 
    ), 
    // 下面显示页面日志 
    array( 
      'class'=>'CWebLogRoute', 
      'levels'=>'trace',   //级别为trace 
      'categories'=>'system.db.*' //只显示关于数据库信息,包括数据库连接,数据库执行语句 
    ),    
  ), 
),

YII_TRACE_LEVEL的数字越大,信息越清楚

二、使用调试工具调试:

yii-debug-toolbar把包解压后 放到extensions里边 然后在配置文件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'), 
     ), 
   ), 
 ),

没有出现的话加上在'components'下的db里加上两个属性,

'enableProfiling'=>true, 
'enableParamLogging'=>true,

然后如果有其他调试工具的插件的话,可能会出现冲突导致sql语句不出来,把那段代码注掉即可。

(急)yii SQL查询出的结果数组转换成AR模式

除了cactivedataprovider,你还可以使用CArrayDataProvider
我给你写个例子:
controller中:
$rawdata = Yii::app()->db->createCommand('select * from {{post}} where idqueryAll();

$data = new CArrayDataProvider($rawdata, array(
'id' => 'user',
'sort' => array(
'attributes' => array(
'id', 'title', 'content'
),
),
'pagination' => array(
'pageSize' => 10,
),
));
$this->render('gridview_array', array('dataProvider' => $data));

然后view中:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'somegrid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'title',
'content',
),
));
这样就ok 了~
 

SQL函数怎调试

就是一个一个实验了, 看看哪个结果返回的是你要的。这种自解释的语言没有什么所谓的调试方法。一条命令就搞定的,你认为怎么算是调试呢
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/840746.htmlTechArticleYii调试SQL的常用方法,yii调试sql Yii调试SQL主要有以下方法: 一、系统自带调试: 首先index.php开启调试模式: // remove the following lines when...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn