Source for file ADOdb.php

Documentation is available at ADOdb.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  ADOdb.php
  5.  *
  6.  *  @package    Ethna
  7.  *  @author     halt feits <halt.feits@gmail.com>
  8.  *  @version    $Id: 6bbc97699c0d61dcb402736b3e8786a46d9b7c74 $
  9.  */
  10.  
  11. /**
  12.  * ADOdb config setting
  13.  */
  14. define('ADODB_OUTP''ethna_adodb_logger')//disable output error
  15.  
  16. require_once 'adodb/adodb.inc.php';
  17.  
  18. function ethna_adodb_logger ($msg$newline{
  19.     $c Ethna_Controller::getInstance();
  20.     $logger $c->getLogger();
  21.  
  22.     $logger->log(LOG_DEBUGstrip_tags(str_replace("\n"""$msg)));
  23. }
  24.  
  25. /**
  26.  *  Ethna_DB_ADOdb
  27.  *
  28.  *  EthnaのフレームワークでADOdbオブジェクトを扱うための抽象クラス
  29.  *
  30.  *  @package    Ethna
  31.  *  @author     halt feits <halt.feits@gmail.com>
  32.  *  @access     public
  33.  */
  34. class Ethna_DB_ADOdb extends Ethna_DB
  35. {
  36.     /**#@+
  37.      *  @access private
  38.      */
  39.  
  40.     /**
  41.      * @XXX stay public because of B.C.
  42.      * @protected    object  DB              DBオブジェクト
  43.      */
  44.     public $db;
  45.  
  46.     /** @protected    string   dsn */
  47.     protected $dsn;
  48.  
  49.     /**#@-*/
  50.  
  51.  
  52.     /**
  53.      *  コンストラクタ
  54.      *
  55.      *  @access public
  56.      *  @param  object  Ethna_Controller    $controller    コントローラオブジェクト
  57.      *  @param  string  $dsn                                DSN
  58.      *  @param  bool    $persistent                         持続接続設定
  59.      */
  60.     public function __construct($controller$dsn$persistent)
  61.     {
  62.         parent::__construct($controller$dsn$persistent);
  63.  
  64.         $this->logger $controller->getLogger();
  65.     }
  66.  
  67.     //{{{ connect
  68.     /**
  69.      *  DBに接続する
  70.      *
  71.      *  @access public
  72.      *  @return bool   true:成功 false:失敗
  73.      */
  74.     public function connect()
  75.     {
  76.         $dsn $this->parseDSN($this->dsn);
  77.  
  78.         if ($dsn['phptype'== 'sqlite'{
  79.             $path $dsn['database'];
  80.             $this->db = ADONewConnection("sqlite");
  81.             $this->db->Connect($path);
  82.         else {
  83.             $this->db = ADONewConnection($this->dsn);
  84.         }
  85.  
  86.         if $this->db {
  87.             $this->db->SetFetchMode(ADODB_FETCH_ASSOC);
  88.             return true;
  89.         else {
  90.             return false;
  91.         }
  92.     }
  93.     //}}}
  94.  
  95.     //{{{ disconnect
  96.     /**
  97.      *  DB接続を切断する
  98.      *
  99.      *  @access public
  100.      */
  101.     public function disconnect()
  102.     {
  103.         //$this->db->close();
  104.         return 0;
  105.     }
  106.     //}}}
  107.  
  108.     //{{{ isValid
  109.     /**
  110.      *  DB接続状態を返す
  111.      *
  112.      *  @access public
  113.      *  @return bool    true:正常(接続済み) false:エラー/未接続
  114.      */
  115.     public function isValid()
  116.     {
  117.         if is_object($this->db) ) {
  118.             return true;
  119.         else {
  120.             return false;
  121.         }
  122.     }
  123.     //}}}
  124.  
  125.     //{{{ begin
  126.     /**
  127.      *  DBトランザクションを開始する
  128.      *
  129.      *  @access public
  130.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  131.      */
  132.     public function begin()
  133.     {
  134.         return $this->db->BeginTrans();
  135.     }
  136.     //}}}
  137.  
  138.     //{{{ rollback
  139.     /**
  140.      *  DBトランザクションを中断する
  141.      *
  142.      *  @access public
  143.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  144.      */
  145.     public function rollback()
  146.     {
  147.         $this->db->RollbackTrans();
  148.         return 0;
  149.     }
  150.     //}}}
  151.  
  152.     //{{{ commit
  153.     /**
  154.      *  DBトランザクションを終了する
  155.      *
  156.      *  @access public
  157.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  158.      */
  159.     public function commit()
  160.     {
  161.         $this->db->CommitTrans();
  162.         return 0;
  163.     }
  164.     //}}}
  165.  
  166.     //{{{ query
  167.     /**
  168.      *  クエリを発行する
  169.      *
  170.      *  @access public
  171.      *  @param  string  $query  SQL文
  172.      *  @return mixed   DB_Result:結果オブジェクト Ethna_Error:エラー
  173.      */
  174.     public function query($query$inputarr false)
  175.     {
  176.         return $this->_query($query$inputarr);
  177.     }
  178.     //}}}
  179.  
  180.     //{{{ _query
  181.     /**
  182.      *  クエリを発行する
  183.      *
  184.      *  @access private
  185.      *  @param  string  $query  SQL文
  186.      *  @return mixed   DB_Result:結果オブジェクト Ethna_Error:エラー
  187.      */
  188.     private function _query($query$inputarr false)
  189.     {
  190.         $this->logger->log(LOG_DEBUG$query);
  191.         $r $this->db->execute($query$inputarr);
  192.  
  193.         if ($r === false{
  194.  
  195.             $error Ethna::raiseError('エラー SQL[%s] CODE[%d] MESSAGE[%s]',
  196.                 E_DB_QUERY,
  197.                 $query,
  198.                 $this->db->ErrorNo(),
  199.                 $this->db->ErrorMsg());
  200.  
  201.             return $error;
  202.  
  203.         }
  204.  
  205.         return $r;
  206.     }
  207.     //}}}
  208.  
  209.     //{{{ getAll
  210.     /**
  211.      *  結果レコードセットを返す
  212.      *
  213.      *  @access public
  214.      *  @param  string $query  SQL
  215.      *  @param  mixed  $inputarr  プレースホルダ(スカラまたは配列)
  216.      *  @return array  $rows   連想配列のリスト
  217.      */
  218.     public function getAll($query$inputarr false)
  219.     {
  220.         $this->db->SetFetchMode(ADODB_FETCH_ASSOC);
  221.         return $this->db->getAll($query$inputarr);
  222.     }
  223.     //}}}
  224.  
  225.     //{{{ getOne
  226.     /**
  227.      *  結果レコードセットのうち第1行第1列目の値を返す
  228.      *
  229.      *  @access public
  230.      *  @param  string  $query  SQL
  231.      *  @param  mixed   $inputarr  プレースホルダ(スカラまたは配列)
  232.      *  @return string  $value
  233.      */
  234.     public function getOne($query$inputarr false)
  235.     {
  236.         return $this->db->GetOne($query$inputarr);
  237.     }
  238.     //}}}
  239.  
  240.     //{{{ getRow
  241.     /**
  242.      *  結果レコードセットのうち第1行目を返す
  243.      *
  244.      *  @access  public
  245.      *  @param   string $query  SQL
  246.      *  @param   mixed  $inputarr  プレースホルダ(スカラまたは配列)
  247.      *  @return  array  $row  連想配列
  248.      */
  249.     public function getRow($query$inputarr false)
  250.     {
  251.         return $this->db->GetRow($query$inputarr);
  252.     }
  253.     //}}}
  254.  
  255.     //{{{ getCol
  256.     /**
  257.      *  結果レコードセットのうち第1列目の値リストを返す
  258.      *
  259.      *  @param   string $query  SQL
  260.      *  @param   mixed  $inputarr  プレースホルダ(スカラまたは配列)
  261.      *  @return  array  $values 値リスト
  262.      */
  263.     public function getCol($query$inputarr false)
  264.     {
  265.         return $this->db->GetCol($query$inputarr);
  266.     }
  267.     //}}}
  268.  
  269.     /**
  270.      *  結果レコードセットを連想配列の連想配列にして返す
  271.      *
  272.      *  @param string $query  SQL
  273.      *  @param mixed  $inputarr  プレースホルダ(スカラまたは配列)
  274.      *  @return array $rows 第一カラムの値をキーとする連想配列
  275.      */
  276.     public function getAssoc($sql$inputarr false$force_array false$first2cols false)
  277.     {
  278.         return $this->db->GetAssoc($sql$inputarr$force_array$first2cols);
  279.     }
  280.  
  281.  
  282.     //{{{ execute
  283.     public function execute($query$inputarr false)
  284.     {
  285.         return $this->db->Execute($query$inputarr);
  286.     }
  287.     //}}}
  288.  
  289.     //{{{ replace
  290.     public function replace($table$arrFields$keyCols$autoQuote false)
  291.     {
  292.         return $this->db->Replace($table$arrFields$keyCols$autoQuote);
  293.     }
  294.     //}}}
  295.  
  296.     //{{{ autoExecute
  297.     public function autoExecute($table$fields$mode$where false$forceUpdate true$magicq false)
  298.     {
  299.         return $this->db->AutoExecute($table$fields$mode$where$forceUpdate$magicq);
  300.     }
  301.     //}}}
  302.  
  303.     //{{{ pageExecute
  304.     /**
  305.      * pageExecute
  306.      *
  307.      * @param string $query 
  308.      * @param string $nrows 
  309.      * @param integer $page 
  310.      * @param array $inputarr 
  311.      */
  312.     public function pageExecute($query$nrows$page$inputarr false)
  313.     {
  314.         return $this->db->PageExecute($query$nrows$page$inputarr);
  315.     }
  316.     //}}}
  317.  
  318. }

Documentation generated on Fri, 11 Nov 2011 03:57:31 +0900 by phpDocumentor 1.4.3