- Timestamp:
- 2007/08/06 11:16:05 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/SC_DbConn.php
r15080 r15208 13 13 class SC_DbConn{ 14 14 15 var $conn; 16 var $result; 17 var $includePath; 18 var $error_mail_to; 19 var $error_mail_title; 20 var $dsn; 21 var $err_disp = true; 22 23 // コンストラクタ 24 function SC_DbConn($dsn = "", $err_disp = true, $new = false){ 25 global $objDbConn; 26 27 // Debugモード指定 28 $options['debug'] = PEAR_DB_DEBUG; 29 // 既に接続されていないか、新規接続要望の場合は接続する。 30 if(!isset($objDbConn->connection) || $new) { 31 if($dsn != "") { 32 $objDbConn = DB::connect($dsn, $options); 33 $this->dsn = $dsn; 34 } else { 35 if(defined('DEFAULT_DSN')) { 36 $objDbConn = DB::connect(DEFAULT_DSN, $options); 37 $this->dsn = DEFAULT_DSN; 38 } else { 39 return; 40 } 41 } 42 } 43 $this->conn = $objDbConn; 44 $this->error_mail_to = DB_ERROR_MAIL_TO; 45 $this->error_mail_title = DB_ERROR_MAIL_SUBJECT; 46 $this->err_disp = $err_disp; 47 } 48 49 // クエリの実行 50 function query($n ,$arr = "", $ignore_err = false){ 51 // mysqlの場合にはビュー表を変換する 52 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 15 var $conn; 16 var $result; 17 var $includePath; 18 var $error_mail_to; 19 var $error_mail_title; 20 var $dsn; 21 var $err_disp = true; 53 22 54 if ( $arr ) { 55 $result = $this->conn->query($n, $arr); 56 } else { 57 $result = $this->conn->query($n); 58 } 59 60 if ($this->conn->isError($result) && !$ignore_err){ 61 $this->send_err_mail ($result, $n); 62 } 63 64 $this->result = $result; 65 return $this->result; 66 } 23 // コンストラクタ 24 function SC_DbConn($dsn = "", $err_disp = true, $new = false){ 25 global $objDbConn; 67 26 68 // 一件のみ取得 69 function getOne($n, $arr = ""){ 70 71 // mysqlの場合にはビュー表を変換する 72 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 73 74 if ( $arr ) { 75 $result = $this->conn->getOne($n, $arr); 76 } else { 77 $result = $this->conn->getOne($n); 78 } 79 if ($this->conn->isError($result)){ 80 $this->send_err_mail ($result ,$n); 81 } 82 $this->result = $result; 83 84 return $this->result; 85 } 86 87 function getRow($n, $arr = ""){ 27 // Debugモード指定 28 $options['debug'] = PEAR_DB_DEBUG; 29 // 既に接続されていないか、新規接続要望の場合は接続する。 30 if(!isset($objDbConn->connection) || $new) { 31 if($dsn != "") { 32 $objDbConn = DB::connect($dsn, $options); 33 $this->dsn = $dsn; 34 } else { 35 if(defined('DEFAULT_DSN')) { 36 $objDbConn = DB::connect(DEFAULT_DSN, $options); 37 $this->dsn = DEFAULT_DSN; 38 } else { 39 return; 40 } 41 } 42 } 43 $this->conn = $objDbConn; 44 $this->error_mail_to = DB_ERROR_MAIL_TO; 45 $this->error_mail_title = DB_ERROR_MAIL_SUBJECT; 46 $this->err_disp = $err_disp; 47 } 88 48 89 // mysqlの場合にはビュー表を変換する 90 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 49 // クエリの実行 50 function query($n ,$arr = "", $ignore_err = false){ 51 // mysqlの場合にはビュー表を変換する 52 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 91 53 92 if ( $arr ) { 93 $result = $this->conn->getRow($n, $arr); 94 } else { 95 $result = $this->conn->getRow($n); 96 } 97 if ($this->conn->isError($result)){ 98 $this->send_err_mail ($result ,$n); 99 } 100 $this->result = $result; 101 return $this->result; 102 } 54 if ( $arr ) { 55 $result = $this->conn->query($n, $arr); 56 } else { 57 $result = $this->conn->query($n); 58 } 103 59 104 // SELECT文の実行結果を全て取得 105 function getAll($n, $arr = ""){ 60 if ($this->conn->isError($result) && !$ignore_err){ 61 $this->send_err_mail ($result, $n); 62 } 106 63 107 // mysqlの場合にはビュー表を変換する 108 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 109 110 if(PEAR::isError($this->conn)) { 111 if(ADMIN_MODE){ 112 sfErrorHeader("DBへの接続に失敗しました。:" . $this->dsn); 113 }else{ 114 sfErrorHeader("DBへの接続に失敗しました。:"); 115 } 116 return 0; 117 } 64 $this->result = $result; 65 return $this->result; 66 } 118 67 119 if ( $arr ){ 120 $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC); 121 } else { 122 $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC); 123 } 124 125 if ($this->conn->isError($result)){ 126 $this->send_err_mail ($result, $n); 127 } 128 $this->result = $result; 129 130 return $this->result; 131 } 132 133 function autoExecute($table_name, $fields_values, $sql_where = null){ 134 135 if ( $sql_where ) { 136 $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where); 137 } else { 138 $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT); 139 } 140 141 if ($this->conn->isError($result)){ 142 $this->send_err_mail ($result, $n); 143 } 144 $this->result = $result; 145 return $this->result; 146 } 147 148 149 function prepare($n){ 150 global $sql; 151 $sql = $n; 152 $result = $this->conn->prepare($n); 153 $this->result = $result; 154 return $this->result; 155 } 156 157 function execute($n, $obj){ 158 global $sql; 159 $sql = $n; 160 $result = $this->conn->execute($n, $obj); 161 $this->result = $result; 162 return $this->result; 163 } 164 165 function reset(){ 166 $this->conn->disconnect(); 167 } 68 // 一件のみ取得 69 function getOne($n, $arr = ""){ 70 71 // mysqlの場合にはビュー表を変換する 72 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 73 74 if ( $arr ) { 75 $result = $this->conn->getOne($n, $arr); 76 } else { 77 $result = $this->conn->getOne($n); 78 } 79 if ($this->conn->isError($result)){ 80 $this->send_err_mail ($result ,$n); 81 } 82 $this->result = $result; 83 84 return $this->result; 85 } 86 87 function getRow($n, $arr = ""){ 88 89 // mysqlの場合にはビュー表を変換する 90 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 91 92 if ( $arr ) { 93 $result = $this->conn->getRow($n, $arr); 94 } else { 95 $result = $this->conn->getRow($n); 96 } 97 if ($this->conn->isError($result)){ 98 $this->send_err_mail ($result ,$n); 99 } 100 $this->result = $result; 101 return $this->result; 102 } 103 104 // SELECT文の実行結果を全て取得 105 function getAll($n, $arr = ""){ 106 107 // mysqlの場合にはビュー表を変換する 108 if (DB_TYPE == "mysql") $n = sfChangeMySQL($n); 109 110 if(PEAR::isError($this->conn)) { 111 if(ADMIN_MODE){ 112 SC_Utils_Ex::sfErrorHeader("DBへの接続に失敗しました。:" . $this->dsn); 113 }else{ 114 SC_Utils_Ex::sfErrorHeader("DBへの接続に失敗しました。:"); 115 } 116 return 0; 117 } 118 119 if ( $arr ){ 120 $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC); 121 } else { 122 $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC); 123 } 124 125 if ($this->conn->isError($result)){ 126 $this->send_err_mail ($result, $n); 127 } 128 $this->result = $result; 129 130 return $this->result; 131 } 132 133 function autoExecute($table_name, $fields_values, $sql_where = null){ 134 135 if ( $sql_where ) { 136 $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where); 137 } else { 138 $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT); 139 } 140 141 if ($this->conn->isError($result)){ 142 $this->send_err_mail ($result, $n); 143 } 144 $this->result = $result; 145 return $this->result; 146 } 147 148 149 function prepare($n){ 150 global $sql; 151 $sql = $n; 152 $result = $this->conn->prepare($n); 153 $this->result = $result; 154 return $this->result; 155 } 156 157 function execute($n, $obj){ 158 global $sql; 159 $sql = $n; 160 $result = $this->conn->execute($n, $obj); 161 $this->result = $result; 162 return $this->result; 163 } 164 165 function reset(){ 166 $this->conn->disconnect(); 167 } 168 168 169 169 function send_err_mail($result, $sql){ 170 170 $url = ''; 171 171 $errmsg = ''; 172 172 173 173 if ($_SERVER['HTTPS'] == "on") { 174 174 $url = "https://"; … … 177 177 } 178 178 $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 179 179 180 180 $errmsg = $url."\n\n"; 181 181 $errmsg .= $sql . "\n"; 182 182 $errmsg .= $result->message . "\n\n"; 183 183 $errmsg .= $result->userinfo . "\n\n"; 184 184 185 185 if ($this->err_disp && DEBUG_MODE === true) { 186 186 print('<pre>'); … … 188 188 print('</pre>'); 189 189 } 190 191 gfDebugLog($errmsg);192 190 191 GC_Utils_Ex::gfDebugLog($errmsg); 192 193 193 exit(); 194 194 }
Note: See TracChangeset
for help on using the changeset viewer.