クエリログ取得
cake/libs/model/datasources/dbo/dbo_mysql_log.phpを作成
<?php
uses("model".DS."datasources".DS."dbo".DS."dbo_mysql");
class DboMysqlLog extends DboMysql{
var $queryNo = 1;
function execute($sql){
$ret = parent::execute($sql);
if(defined("LOG_SQL") && LOG_SQL){
$this->log(sprintf("%d.%s",$this->queryNo,$sql),SQL);
$this->queryNo++;
}
return $ret;
}
}
app/config/database.php の 'driver' => 'mysql_log' にする
var $default = array(
'driver' => 'mysql_log',
'persistent' => false,
'host' => 'localhost',
'login' => 'verynight',
'password' => 'xxxxxx',
'database' => 'database',
'prefix' => '',
'encoding' => 'utf-8'
);
app/config/bootstrap.php で定数 LOG_SQL を設定(define)する
// set LOG_SQL
define('LOG_SQL', true);
app/tmp/logs/SQL.log が出力される
~
2011-04-18 1:11:55 Sql: 1.SHOW FULL COLUMNS FROM `tables`
2011-04-18 1:11:56 Sql: 2.SELECT COUNT(*) AS `count` FROM `tables` AS `Table` WHERE `Table`.`id` = 1
~