[18390] | 1 | Index: SC_DbConn.php |
---|
| 2 | =================================================================== |
---|
| 3 | --- data/class/SC_DbConn.php (revision 18367) |
---|
| 4 | +++ data/class/SC_DbConn.php (working copy) |
---|
| 5 | @@ -22,15 +22,20 @@ |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | $current_dir = realpath(dirname(__FILE__)); |
---|
| 9 | -require_once($current_dir . "/../module/DB.php"); |
---|
| 10 | +require_once($current_dir . "/../module/adodb/adodb.inc.php"); |
---|
| 11 | +define('ADODB_ERROR_HANDLER_TYPE', E_USER_ERROR); |
---|
| 12 | +define('ADODB_ERROR_LOG_TYPE',3); |
---|
| 13 | +define('ADODB_ERROR_LOG_DEST', DATA_PATH . "logs/error.log"); |
---|
| 14 | +require_once($current_dir . "/../module/adodb/adodb-errorhandler.inc.php"); |
---|
| 15 | +require_once($current_dir . "/../module/adodb/adodb-errorpear.inc.php"); |
---|
| 16 | |
---|
| 17 | -$objDbConn = ""; |
---|
| 18 | - |
---|
| 19 | +/** |
---|
| 20 | + * FIXME インストーラ要修正 |
---|
| 21 | + */ |
---|
| 22 | class SC_DbConn { |
---|
| 23 | |
---|
| 24 | var $conn; |
---|
| 25 | var $result; |
---|
| 26 | - var $includePath; |
---|
| 27 | var $dsn; |
---|
| 28 | var $err_disp = true; |
---|
| 29 | var $dbFactory; |
---|
| 30 | @@ -38,33 +43,39 @@ |
---|
| 31 | |
---|
| 32 | // コンストラクタ |
---|
| 33 | function SC_DbConn($dsn = "", $err_disp = true, $new = false){ |
---|
| 34 | - global $objDbConn; |
---|
| 35 | |
---|
| 36 | - // Debugモード指定 |
---|
| 37 | - $options['debug'] = PEAR_DB_DEBUG; |
---|
| 38 | - // 持続的接続オプション |
---|
| 39 | - $options['persistent'] = PEAR_DB_PERSISTENT; |
---|
| 40 | - |
---|
| 41 | - // 既に接続されていないか、新規接続要望の場合は接続する。 |
---|
| 42 | - if(!isset($objDbConn->connection) || $new) { |
---|
| 43 | - if($dsn != "") { |
---|
| 44 | - $objDbConn = DB::connect($dsn, $options); |
---|
| 45 | - $this->dsn = $dsn; |
---|
| 46 | + if (empty($dsn)) { |
---|
| 47 | + if (defined('DEFAULT_DSN')) { |
---|
| 48 | + $dsn = DEFAULT_DSN; |
---|
| 49 | } else { |
---|
| 50 | - if(defined('DEFAULT_DSN')) { |
---|
| 51 | - $objDbConn = DB::connect(DEFAULT_DSN, $options); |
---|
| 52 | - $this->dsn = DEFAULT_DSN; |
---|
| 53 | - } else { |
---|
| 54 | - return; |
---|
| 55 | - } |
---|
| 56 | + return; |
---|
| 57 | } |
---|
| 58 | + // 接続オプションのために "?" をつける |
---|
| 59 | + $this->dsn = $dsn . "?"; |
---|
| 60 | + } |
---|
| 61 | + |
---|
| 62 | + if (!empty($this->dsn)) { |
---|
| 63 | + // 持続的接続モード指定 |
---|
| 64 | + if (PEAR_DB_PERSISTENT) { |
---|
| 65 | + $this->dsn = $this->dsn . "&persist"; |
---|
| 66 | } |
---|
| 67 | - |
---|
| 68 | - if (DB_TYPE == 'mysql') { |
---|
| 69 | - $objDbConn->query('SET NAMES utf8'); |
---|
| 70 | + // Debug モード指定 |
---|
| 71 | + if(PEAR_DB_DEBUG > 0) { |
---|
| 72 | + $this->dsn = $this->dsn . "&debug"; |
---|
| 73 | } |
---|
| 74 | - |
---|
| 75 | - $this->conn = $objDbConn; |
---|
| 76 | + // 常に新規接続 |
---|
| 77 | + if ($new) { |
---|
| 78 | + $this->dsn = $this->dsn . "&new"; |
---|
| 79 | + } |
---|
| 80 | + } |
---|
| 81 | + |
---|
| 82 | + $this->conn =& ADONewConnection($this->dsn); |
---|
| 83 | + $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); |
---|
| 84 | + |
---|
| 85 | + if (DB_TYPE == 'mysql') { |
---|
| 86 | + $this->conn->Execute('SET NAMES utf8'); |
---|
| 87 | + } |
---|
| 88 | + |
---|
| 89 | $this->err_disp = $err_disp; |
---|
| 90 | $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
| 91 | } |
---|
| 92 | @@ -75,13 +86,13 @@ |
---|
| 93 | if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); |
---|
| 94 | |
---|
| 95 | if ( $arr ) { |
---|
| 96 | - $result = $this->conn->query($n, $arr); |
---|
| 97 | + $result = $this->conn->Execute($n, $arr); |
---|
| 98 | } else { |
---|
| 99 | - $result = $this->conn->query($n); |
---|
| 100 | + $result = $this->conn->Execute($n); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | - if ($this->conn->isError($result) && !$ignore_err){ |
---|
| 104 | - $this->send_err_mail($result, $n); |
---|
| 105 | + if ($this->conn->ErrorNo() < 0 && !$ignore_err){ |
---|
| 106 | + return ADODB_Pear_Error(); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | $this->result = $result; |
---|
| 110 | @@ -99,9 +110,10 @@ |
---|
| 111 | } else { |
---|
| 112 | $result = $this->conn->getOne($n); |
---|
| 113 | } |
---|
| 114 | - if ($this->conn->isError($result)){ |
---|
| 115 | - $this->send_err_mail($result ,$n); |
---|
| 116 | + if ($this->conn->ErrorNo() < 0) { |
---|
| 117 | + return ADODB_Pear_Error(); |
---|
| 118 | } |
---|
| 119 | + |
---|
| 120 | $this->result = $result; |
---|
| 121 | |
---|
| 122 | return $this->result; |
---|
| 123 | @@ -122,9 +134,10 @@ |
---|
| 124 | |
---|
| 125 | $result = $this->conn->getRow($sql, $arrVal ,$fetchmode); |
---|
| 126 | |
---|
| 127 | - if ($this->conn->isError($result)){ |
---|
| 128 | - $this->send_err_mail($result ,$sql); |
---|
| 129 | + if ($this->conn->ErrorNo() < 0) { |
---|
| 130 | + return ADODB_Pear_Error(); |
---|
| 131 | } |
---|
| 132 | + |
---|
| 133 | $this->result = $result; |
---|
| 134 | return $this->result; |
---|
| 135 | } |
---|
| 136 | @@ -135,13 +148,15 @@ |
---|
| 137 | if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); |
---|
| 138 | |
---|
| 139 | if ($arr) { |
---|
| 140 | - $result = $this->conn->getCol($n, $col, $arr); |
---|
| 141 | + $result = $this->conn->GetCol($n, $arr); |
---|
| 142 | } else { |
---|
| 143 | - $result = $this->conn->getCol($n, $col); |
---|
| 144 | + $result = $this->conn->GetCol($n); |
---|
| 145 | } |
---|
| 146 | - if ($this->conn->isError($result)) { |
---|
| 147 | - $this->send_err_mail($result, $n); |
---|
| 148 | + |
---|
| 149 | + if ($this->conn->ErrorNo() < 0) { |
---|
| 150 | + return ADODB_Pear_Error(); |
---|
| 151 | } |
---|
| 152 | + |
---|
| 153 | $this->result = $result; |
---|
| 154 | return $this->result; |
---|
| 155 | } |
---|
| 156 | @@ -160,16 +175,16 @@ |
---|
| 157 | } |
---|
| 158 | return 0; |
---|
| 159 | } |
---|
| 160 | - |
---|
| 161 | if ( $arr ){ |
---|
| 162 | - $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC); |
---|
| 163 | + $result = $this->conn->GetAll($n, $arr); |
---|
| 164 | } else { |
---|
| 165 | - $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC); |
---|
| 166 | + $result = $this->conn->GetAll($n); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | - if ($this->conn->isError($result)){ |
---|
| 170 | - $this->send_err_mail($result, $n); |
---|
| 171 | + if ($this->conn->ErrorNo() < 0) { |
---|
| 172 | + return ADODB_Pear_Error(); |
---|
| 173 | } |
---|
| 174 | + |
---|
| 175 | $this->result = $result; |
---|
| 176 | |
---|
| 177 | return $this->result; |
---|
| 178 | @@ -178,19 +193,23 @@ |
---|
| 179 | function autoExecute($table_name, $fields_values, $sql_where = null){ |
---|
| 180 | |
---|
| 181 | if ( $sql_where ) { |
---|
| 182 | - $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where); |
---|
| 183 | + $result = $this->conn->autoExecute( $table_name, $fields_values, 'UPDATE', $sql_where); |
---|
| 184 | } else { |
---|
| 185 | - $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT); |
---|
| 186 | + $result = $this->conn->autoExecute( $table_name, $fields_values, 'INSERT'); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | - if ($this->conn->isError($result)){ |
---|
| 190 | - $this->send_err_mail($result, $n); |
---|
| 191 | + if ($this->conn->ErrorNo() < 0) { |
---|
| 192 | + return ADODB_Pear_Error(); |
---|
| 193 | } |
---|
| 194 | - $this->result = $result; |
---|
| 195 | - return $this->result; |
---|
| 196 | + |
---|
| 197 | + return 1; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | - |
---|
| 201 | + /** |
---|
| 202 | + * XXX バックエンドが ADOdb の場合は動作しません. |
---|
| 203 | + * |
---|
| 204 | + * @deprecated 本体で未使用のため非推奨 |
---|
| 205 | + */ |
---|
| 206 | function prepare($n){ |
---|
| 207 | global $sql; |
---|
| 208 | $sql = $n; |
---|
| 209 | @@ -199,6 +218,11 @@ |
---|
| 210 | return $this->result; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | + /** |
---|
| 214 | + * XXX バックエンドが ADOdb の場合は動作しません. |
---|
| 215 | + * |
---|
| 216 | + * @deprecated 本体で未使用のため非推奨 |
---|
| 217 | + */ |
---|
| 218 | function execute($n, $obj){ |
---|
| 219 | global $sql; |
---|
| 220 | $sql = $n; |
---|
| 221 | @@ -207,6 +231,11 @@ |
---|
| 222 | return $this->result; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | + /** |
---|
| 226 | + * XXX バックエンドが ADOdb の場合は動作しません. |
---|
| 227 | + * |
---|
| 228 | + * @deprecated 本体で未使用のため非推奨 |
---|
| 229 | + */ |
---|
| 230 | function reset(){ |
---|
| 231 | $this->conn->disconnect(); |
---|
| 232 | } |
---|
| 233 | @@ -221,13 +250,15 @@ |
---|
| 234 | $objPage->pearResult = $pearResult; |
---|
| 235 | GC_Utils_Ex::gfPrintLog($objPage->sfGetErrMsg()); |
---|
| 236 | $objPage->process(); |
---|
| 237 | - |
---|
| 238 | - exit(); |
---|
| 239 | + exit; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | /** |
---|
| 243 | * 直前に実行されたSQL文を取得する. |
---|
| 244 | * |
---|
| 245 | + * XXX バックエンドが ADOdb の場合は動作しません. |
---|
| 246 | + * |
---|
| 247 | + * @deprecated PEAR_DB_DEBUG = 1 で代用して下さい. |
---|
| 248 | * @param boolean $disp trueの場合、画面出力を行う. |
---|
| 249 | * @return string SQL文 |
---|
| 250 | */ |
---|