source:
branches/comu-ver2/patches/MDB2.patch
@
18755
Revision 18755, 6.9 KB checked in by nanasess, 14 years ago (diff) | |
---|---|
|
-
html/define.php
2 2 /** HTMLディレクトリからのDATAディレクトリの相対パス */ 3 3 define("HTML2DATA_DIR", "../data/"); 4 4 5 /** data/module 以下の PEAR ライブラリのみを使用する */ 6 set_include_path(realpath(dirname(__FILE__) . "/" . HTML2DATA_DIR . "module")); 7 5 8 /** 6 9 * DIR_INDEX_FILE にアクセスするときにファイル名を使用するか 7 10 * -
data/class/SC_DbConn.php
22 22 */ 23 23 24 24 $current_dir = realpath(dirname(__FILE__)); 25 require_once($current_dir . "/../module/ DB.php");25 require_once($current_dir . "/../module/MDB2.php"); 26 26 27 27 $g_arr_objDbConn = array(); 28 28 … … 60 60 } 61 61 62 62 if ($new) { 63 $this->conn = DB::connect($this->dsn, $options); 63 // TODO singleton の方が良いかも 64 $this->conn = MDB2::connect($this->dsn, $options); 64 65 $g_arr_objDbConn[$this->dsn] = $this->conn; 65 66 67 // TODO MDB2::setCharset() を使った方が良い? 66 68 if (DB_TYPE == 'mysql') { 67 69 $g_arr_objDbConn[$this->dsn]->query('SET NAMES utf8'); // FIXME mysql_set_charset を使える環境では、その方が良さそう (2010/03/03 Seasoft 塚田) 68 70 $g_arr_objDbConn[$this->dsn]->query("SET SESSION sql_mode = 'ANSI'"); … … 71 73 $this->conn = $g_arr_objDbConn[$this->dsn]; 72 74 } 73 75 76 $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); 74 77 $this->err_disp = $err_disp; 75 78 $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); 76 79 } 77 80 78 81 // クエリの実行 79 function query($n ,$arr = "", $ignore_err = false){82 function query($n ,$arr = array(), $ignore_err = false){ 80 83 // mysqlの場合にはビュー表を変換する 81 84 if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 82 85 86 $sth = $this->conn->prepare($n); 83 87 if ( $arr ) { 84 $result = $ this->conn->query($n,$arr);88 $result = $sth->execute($arr); 85 89 } else { 86 $result = $ this->conn->query($n);90 $result = $sth->execute(); 87 91 } 88 92 89 93 if ($this->conn->isError($result) && !$ignore_err){ … … 95 99 } 96 100 97 101 // 一件のみ取得 98 function getOne($n, $arr = ""){102 function getOne($n, $arr = array()){ 99 103 100 104 // mysqlの場合にはビュー表を変換する 101 105 if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 102 106 107 $sth = $this->conn->prepare($n); 103 108 if ( $arr ) { 104 $ result = $this->conn->getOne($n,$arr);109 $affected = $sth->execute($arr); 105 110 } else { 106 $ result = $this->conn->getOne($n);111 $affected = $sth->execute(); 107 112 } 108 if ($this->conn->isError($result)){ 109 $this->send_err_mail($result ,$n); 113 114 if ($this->conn->isError($affected)){ 115 $this->send_err_mail($affected ,$n); 110 116 } 111 $this->result = $result; 112 117 $this->result = $affected->fetchOne(); 113 118 return $this->result; 114 119 } 115 120 … … 125 130 126 131 // mysqlの場合にはビュー表を変換する 127 132 if (DB_TYPE == "mysql") $sql = $this->dbFactory->sfChangeMySQL($sql); 133 134 $sth = $this->conn->prepare($n); 135 if ($arr) { 136 $affected = $sth->execute($arr); 137 } else { 138 $affected = $sth->execute(); 139 } 140 if ($this->conn->isError($affected)) { 141 $this->send_err_mail($affected, $n); 142 } 143 $this->result = $affected->fetchRow($fetchmode); 128 144 129 $result = $this->conn->getRow($sql, $arrVal ,$fetchmode);130 131 if ($this->conn->isError($result)){132 $this->send_err_mail($result ,$sql);133 }134 $this->result = $result;135 145 return $this->result; 136 146 } 137 147 138 function getCol($n, $col, $arr = "") {148 function getCol($n, $col, $arr = array()) { 139 149 140 150 // mysqlの場合にはビュー表を変換する 141 151 if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 142 152 153 $sth = $this->conn->prepare($n); 143 154 if ($arr) { 144 $ result = $this->conn->getCol($n, $col,$arr);155 $affected = $sth->execute($arr); 145 156 } else { 146 $ result = $this->conn->getCol($n, $col);157 $affected = $sth->execute(); 147 158 } 148 if ($this->conn->isError($ result)) {149 $this->send_err_mail($ result, $n);159 if ($this->conn->isError($affected)) { 160 $this->send_err_mail($affected, $n); 150 161 } 151 $this->result = $ result;162 $this->result = $affected->fetchCol($col); 152 163 return $this->result; 153 164 } 154 165 … … 160 171 * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 161 172 * @return array データを含む2次元配列。失敗した場合に 0 または DB_Error オブジェクトを返します。 162 173 */ 163 function getAll($sql, $arrVal = "", $fetchmode = DB_FETCHMODE_ASSOC) {174 function getAll($sql, $arrVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 164 175 165 176 // mysqlの場合にはビュー表を変換する 166 177 if (DB_TYPE == "mysql") $sql = $this->dbFactory->sfChangeMySQL($sql); … … 175 186 return 0; 176 187 } 177 188 189 $sth = $this->conn->prepare($sql); 190 178 191 if ($arrVal) { // FIXME 判定が曖昧 179 $ result = $this->conn->getAll($sql, $arrVal, $fetchmode);192 $affected = $sth->execute($arrVal); 180 193 } else { 181 $ result = $this->conn->getAll($sql, $fetchmode);194 $affected = $sth->execute(); 182 195 } 183 196 184 if ($this->conn->isError($ result)) {185 $this->send_err_mail($ result, $sql);197 if ($this->conn->isError($affected)) { 198 $this->send_err_mail($affected, $sql); 186 199 } 187 $this->result = $ result;200 $this->result = $affected->fetchAll($fetchmode); 188 201 189 202 return $this->result; 190 203 } -
data/class/SC_Query.php
88 88 * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 89 89 * @return array|null 90 90 */ 91 function select($col, $table, $where = "", $arrval = array(), $fetchmode = DB_FETCHMODE_ASSOC) {91 function select($col, $table, $where = "", $arrval = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 92 92 $sqlse = $this->getSql($col, $table, $where); 93 93 $ret = $this->conn->getAll($sqlse, $arrval, $fetchmode); 94 94 95 return $ret; 95 96 } 96 97
Note: See TracBrowser
for help on using the repository browser.