Changeset 15078 for branches/feature-module-update/data/class/SC_Query.php
- Timestamp:
- 2007/07/20 15:58:59 (17 years ago)
- Location:
- branches/feature-module-update
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update
-
Property
svn:ignore
set to
.cache
.settings
.projectOptions
-
Property
svn:ignore
set to
-
branches/feature-module-update/data/class/SC_Query.php
r14921 r15078 13 13 var $order; 14 14 15 // ¥³¥ó¥¹¥È¥é¥¯¥¿15 // コンストラクタ 16 16 /* 17 $err_disp: ¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤«18 $new ¡§¿·µ¬¤ËÀܳ¤ò¹Ô¤¦¤«17 $err_disp:エラー表示を行うか 18 $new:新規に接続を行うか 19 19 */ 20 20 function SC_Query($dsn = "", $err_disp = true, $new = false) { … … 24 24 } 25 25 26 // ¥¨¥é¡¼È½Äê26 // エラー判定 27 27 function isError() { 28 28 if(PEAR::isError($this->conn->conn)) { … … 32 32 } 33 33 34 // COUNT ʸ¤Î¼Â¹Ô34 // COUNT文の実行 35 35 function count($table, $where = "", $arrval = array()) { 36 36 if(strlen($where) <= 0) { … … 39 39 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 40 40 } 41 // ¥«¥¦¥ó¥Èʸ¤Î¼Â¹Ô41 // カウント文の実行 42 42 $ret = $this->conn->getOne($sqlse, $arrval); 43 43 return $ret; … … 107 107 function getsql($col, $table, $where) { 108 108 if($where != "") { 109 // °ú¿ô¤Î$where¤òÍ¥À褷¤Æ¼Â¹Ô¤¹¤ë¡£109 // 引数の$whereを優先して実行する。 110 110 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 111 111 } else { … … 179 179 180 180 181 // INSERT ʸ¤ÎÀ¸À®¡¦¼Â¹Ô182 // $table : ¥Æ¡¼¥Ö¥ë̾183 // $sqlval : Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó181 // INSERT文の生成・実行 182 // $table :テーブル名 183 // $sqlval :列名 => 値の格納されたハッシュ配列 184 184 function insert($table, $sqlval) { 185 185 $strcol = ''; … … 206 206 return false; 207 207 } 208 // ʸËö¤Î","¤òºï½ü208 // 文末の","を削除 209 209 $strcol = ereg_replace(",$","",$strcol); 210 // ʸËö¤Î","¤òºï½ü210 // 文末の","を削除 211 211 $strval = ereg_replace(",$","",$strval); 212 212 $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 213 213 214 // INSERT ʸ¤Î¼Â¹Ô214 // INSERT文の実行 215 215 $ret = $this->conn->query($sqlin, $arrval); 216 216 … … 218 218 } 219 219 220 // INSERT ʸ¤ÎÀ¸À®¡¦¼Â¹Ô221 // $table : ¥Æ¡¼¥Ö¥ë̾222 // $sqlval : Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó220 // INSERT文の生成・実行 221 // $table :テーブル名 222 // $sqlval :列名 => 値の格納されたハッシュ配列 223 223 function fast_insert($table, $sqlval) { 224 224 $strcol = ''; … … 239 239 return false; 240 240 } 241 // ʸËö¤Î","¤òºï½ü241 // 文末の","を削除 242 242 $strcol = ereg_replace(",$","",$strcol); 243 // ʸËö¤Î","¤òºï½ü243 // 文末の","を削除 244 244 $strval = ereg_replace(",$","",$strval); 245 245 $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 246 246 247 // INSERT ʸ¤Î¼Â¹Ô247 // INSERT文の実行 248 248 $ret = $this->conn->query($sqlin); 249 249 … … 252 252 253 253 254 // UPDATE ʸ¤ÎÀ¸À®¡¦¼Â¹Ô255 // $table : ¥Æ¡¼¥Ö¥ë̾256 // $sqlval : Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó257 // $where :WHERE ʸ»úÎó254 // UPDATE文の生成・実行 255 // $table :テーブル名 256 // $sqlval :列名 => 値の格納されたハッシュ配列 257 // $where :WHERE文字列 258 258 function update($table, $sqlval, $where = "", $arradd = "", $addcol = "") { 259 259 $strcol = ''; … … 283 283 } 284 284 285 // ʸËö¤Î","¤òºï½ü285 // 文末の","を削除 286 286 $strcol = ereg_replace(",$","",$strcol); 287 // ʸËö¤Î","¤òºï½ü287 // 文末の","を削除 288 288 $strval = ereg_replace(",$","",$strval); 289 289 … … 295 295 296 296 if(is_array($arradd)) { 297 // ¥×¥ì¡¼¥¹¥Û¥ë¥À¡¼ÍѤËÇÛÎó¤òÄɲÃ297 // プレースホルダー用に配列を追加 298 298 foreach($arradd as $val) { 299 299 $arrval[] = $val; … … 301 301 } 302 302 303 // INSERT ʸ¤Î¼Â¹Ô303 // INSERT文の実行 304 304 $ret = $this->conn->query($sqlup, $arrval); 305 305 return $ret; 306 306 } 307 307 308 // MAX ʸ¤Î¼Â¹Ô308 // MAX文の実行 309 309 function max($table, $col, $where = "", $arrval = array()) { 310 310 if(strlen($where) <= 0) { … … 313 313 $sqlse = "SELECT MAX($col) FROM $table WHERE $where"; 314 314 } 315 // MAX ʸ¤Î¼Â¹Ô315 // MAX文の実行 316 316 $ret = $this->conn->getOne($sqlse, $arrval); 317 317 return $ret; 318 318 } 319 319 320 // MIN ʸ¤Î¼Â¹Ô320 // MIN文の実行 321 321 function min($table, $col, $where = "", $arrval = array()) { 322 322 if(strlen($where) <= 0) { … … 325 325 $sqlse = "SELECT MIN($col) FROM $table WHERE $where"; 326 326 } 327 // MIN ʸ¤Î¼Â¹Ô327 // MIN文の実行 328 328 $ret = $this->conn->getOne($sqlse, $arrval); 329 329 return $ret; 330 330 } 331 331 332 // ÆÃÄê¤Î¥«¥é¥à¤ÎÃͤò¼èÆÀ332 // 特定のカラムの値を取得 333 333 function get($table, $col, $where = "", $arrval = array()) { 334 334 if(strlen($where) <= 0) { … … 337 337 $sqlse = "SELECT $col FROM $table WHERE $where"; 338 338 } 339 // SQL ʸ¤Î¼Â¹Ô339 // SQL文の実行 340 340 $ret = $this->conn->getOne($sqlse, $arrval); 341 341 return $ret; … … 343 343 344 344 function getone($sql, $arrval = array()) { 345 // SQL ʸ¤Î¼Â¹Ô345 // SQL文の実行 346 346 $ret = $this->conn->getOne($sql, $arrval); 347 347 return $ret; … … 349 349 } 350 350 351 // °ì¹Ô¤ò¼èÆÀ351 // 一行を取得 352 352 function getrow($table, $col, $where = "", $arrval = array()) { 353 353 if(strlen($where) <= 0) { … … 356 356 $sqlse = "SELECT $col FROM $table WHERE $where"; 357 357 } 358 // SQL ʸ¤Î¼Â¹Ô358 // SQL文の実行 359 359 $ret = $this->conn->getRow($sqlse, $arrval); 360 360 … … 362 362 } 363 363 364 // ¥ì¥³¡¼¥É¤Îºï½ü364 // レコードの削除 365 365 function delete($table, $where = "", $arrval = array()) { 366 366 if(strlen($where) <= 0) { … … 375 375 function nextval($table, $colname) { 376 376 $sql = ""; 377 // postgresql ¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë377 // postgresqlとmysqlとで処理を分ける 378 378 if (DB_TYPE == "pgsql") { 379 379 $seqtable = $table . "_" . $colname . "_seq"; … … 419 419 } 420 420 421 // auto_increment ¤ò¼èÆÀ¤¹¤ë421 // auto_incrementを取得する 422 422 function get_auto_increment($table_name){ 423 // ¥í¥Ã¥¯¤¹¤ë423 // ロックする 424 424 $this->query("LOCK TABLES $table_name WRITE"); 425 425 426 // ¼¡¤ÎIncrement¤ò¼èÆÀ426 // 次のIncrementを取得 427 427 $arrRet = $this->getAll("SHOW TABLE STATUS LIKE ?", array($table_name)); 428 428 $auto_inc_no = $arrRet[0]["Auto_increment"]; 429 429 430 // Ãͤò¥«¥¦¥ó¥È¥¢¥Ã¥×¤·¤Æ¤ª¤¯430 // 値をカウントアップしておく 431 431 $this->conn->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1); 432 432 433 // ²ò½ü¤¹¤ë433 // 解除する 434 434 $this->query('UNLOCK TABLES'); 435 435
Note: See TracChangeset
for help on using the changeset viewer.