Ethna_DB_ADOdbで、ADOdbのデバッグモードを使う

実行したSQLやエラー情報を画面に出したかったので。

  • まず、プロジェクト名/etc/プロジェクト名-ini.phpにて、$configにフラグ追加。
<?php
$config = array(
    'adodb_debug' => true,    //trueの時、画面に実行したSQLを出力する。
);

?>
  • 次に、Ethna/class/DB/Ethna_DB_ADOdb.phpをちょっといじる。
<?php
- define('ADODB_OUTP', 'sprintf'); //disable output error
+ //define('ADODB_OUTP', 'sprintf'); //disable output error

class Ethna_DB_ADOdb extends Ethna_DB
{
+    /**
+     *  @var    bool    trueならdebugモード。
+     */
+    var $debug;


    function Ethna_DB_ADOdb(&$controller, $dsn, $persistent)
    {
        parent::Ethna_DB($controller, $dsn, $persistent);

        $this->logger =& $controller->getLogger();
+       // 設定を受け取る。
+       $this->debug = $controller->config->get( 'adodb_debug' );
    }


    //{{{ connect
    /**
     *  DBに接続する
     *
     *  @access public
     *  @return mixed   0:正常終了 Ethna_Error:エラー
     */
    function connect()
    {
        $dsn = $this->parseDSN($this->dsn);
        
        if ($dsn['phptype'] == 'sqlite') {
            $path = $dsn['database'];
            $this->db = ADONewConnection("sqlite");
            $this->db->Connect($path);
        } else {
            $this->db = ADONewConnection($this->dsn);
        }

        if ( $this->db ) {
            $this->db->SetFetchMode(ADODB_FETCH_ASSOC);
+           // デバッグモードの設定。
+           $this->db->debug = $this->debug;
            return true;
        } else {
            return false;
        }    
    }
?>


できあがり。PHP5にしたからPDOで行こうかと思ったけど、やっぱりADOdbかなー。