Yii調試SQL的常用方法,yii調試sql_PHP教程

來源:互聯網
上載者:User

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 id<100')->queryAll();

$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函數怎調試

就是一個一個實驗了, 看看哪個結果返回的是你要的。這種自解釋的語言沒有什麼所謂的調試方法。一條命令就搞定的,你認為怎麼算是調試呢
 

http://www.bkjia.com/PHPjc/840746.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/840746.htmlTechArticleYii調試SQL的常用方法,yii調試sql Yii調試SQL主要有以下方法: 一、系統內建調試: 首先index.php開啟偵錯模式: // remove the following lines when...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.