Changeset 11729 for branches/comu/data/class/SC_Query.php
- Timestamp:
- 2007/03/10 21:35:02 (20 years ago)
- File:
-
- 1 edited
-
branches/comu/data/class/SC_Query.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/comu/data/class/SC_Query.php
r15 r11729 11 11 var $conn; 12 12 13 // ¥³¥ó¥¹¥È¥é¥¯¥¿13 // コンストラクタ 14 14 /* 15 $err_disp: ¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤«16 $new ¡§¿·µ¬¤ËÀܳ¤ò¹Ô¤¦¤«15 $err_disp:エラー表示を行うか 16 $new:新規に接続を行うか 17 17 */ 18 18 function SC_Query($dsn = "", $err_disp = true, $new = false) { … … 22 22 } 23 23 24 // ¥¨¥é¡¼È½Äê24 // エラー判定 25 25 function isError() { 26 26 if(PEAR::isError($this->conn->conn)) { … … 30 30 } 31 31 32 // COUNT ʸ¤Î¼Â¹Ô32 // COUNT文の実行 33 33 function count($table, $where = "", $arrval = array()) { 34 34 if(strlen($where) <= 0) { … … 37 37 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 38 38 } 39 // ¥«¥¦¥ó¥Èʸ¤Î¼Â¹Ô39 // カウント文の実行 40 40 $ret = $this->conn->getOne($sqlse, $arrval); 41 41 return $ret; … … 105 105 function getsql($col, $table, $where) { 106 106 if($where != "") { 107 // °ú¿ô¤Î$where¤òÍ¥À褷¤Æ¼Â¹Ô¤¹¤ë¡£107 // 引数の$whereを優先して実行する。 108 108 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 109 109 } else { … … 177 177 178 178 179 // INSERT ʸ¤ÎÀ¸À®¡¦¼Â¹Ô180 // $table : ¥Æ¡¼¥Ö¥ë̾181 // $sqlval : Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó179 // INSERT文の生成・実行 180 // $table :テーブル名 181 // $sqlval :列名 => 値の格納されたハッシュ配列 182 182 function insert($table, $sqlval) { 183 183 $strcol = ''; … … 204 204 return false; 205 205 } 206 // ʸËö¤Î","¤òºï½ü206 // 文末の","を削除 207 207 $strcol = ereg_replace(",$","",$strcol); 208 // ʸËö¤Î","¤òºï½ü208 // 文末の","を削除 209 209 $strval = ereg_replace(",$","",$strval); 210 210 $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 211 211 212 // INSERT ʸ¤Î¼Â¹Ô212 // INSERT文の実行 213 213 $ret = $this->conn->query($sqlin, $arrval); 214 214 … … 216 216 } 217 217 218 // INSERT ʸ¤ÎÀ¸À®¡¦¼Â¹Ô219 // $table : ¥Æ¡¼¥Ö¥ë̾220 // $sqlval : Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó218 // INSERT文の生成・実行 219 // $table :テーブル名 220 // $sqlval :列名 => 値の格納されたハッシュ配列 221 221 function fast_insert($table, $sqlval) { 222 222 $strcol = ''; … … 237 237 return false; 238 238 } 239 // ʸËö¤Î","¤òºï½ü239 // 文末の","を削除 240 240 $strcol = ereg_replace(",$","",$strcol); 241 // ʸËö¤Î","¤òºï½ü241 // 文末の","を削除 242 242 $strval = ereg_replace(",$","",$strval); 243 243 $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 244 244 245 // INSERT ʸ¤Î¼Â¹Ô245 // INSERT文の実行 246 246 $ret = $this->conn->query($sqlin); 247 247 … … 250 250 251 251 252 // UPDATE ʸ¤ÎÀ¸À®¡¦¼Â¹Ô253 // $table : ¥Æ¡¼¥Ö¥ë̾254 // $sqlval : Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó255 // $where :WHERE ʸ»úÎó252 // UPDATE文の生成・実行 253 // $table :テーブル名 254 // $sqlval :列名 => 値の格納されたハッシュ配列 255 // $where :WHERE文字列 256 256 function update($table, $sqlval, $where = "", $arradd = "", $addcol = "") { 257 257 $strcol = ''; … … 281 281 } 282 282 283 // ʸËö¤Î","¤òºï½ü283 // 文末の","を削除 284 284 $strcol = ereg_replace(",$","",$strcol); 285 // ʸËö¤Î","¤òºï½ü285 // 文末の","を削除 286 286 $strval = ereg_replace(",$","",$strval); 287 287 … … 293 293 294 294 if(is_array($arradd)) { 295 // ¥×¥ì¡¼¥¹¥Û¥ë¥À¡¼ÍѤËÇÛÎó¤òÄɲÃ295 // プレースホルダー用に配列を追加 296 296 foreach($arradd as $val) { 297 297 $arrval[] = $val; … … 299 299 } 300 300 301 // INSERT ʸ¤Î¼Â¹Ô301 // INSERT文の実行 302 302 $ret = $this->conn->query($sqlup, $arrval); 303 303 return $ret; 304 304 } 305 305 306 // MAX ʸ¤Î¼Â¹Ô306 // MAX文の実行 307 307 function max($table, $col, $where = "", $arrval = array()) { 308 308 if(strlen($where) <= 0) { … … 311 311 $sqlse = "SELECT MAX($col) FROM $table WHERE $where"; 312 312 } 313 // MAX ʸ¤Î¼Â¹Ô313 // MAX文の実行 314 314 $ret = $this->conn->getOne($sqlse, $arrval); 315 315 return $ret; 316 316 } 317 317 318 // MIN ʸ¤Î¼Â¹Ô318 // MIN文の実行 319 319 function min($table, $col, $where = "", $arrval = array()) { 320 320 if(strlen($where) <= 0) { … … 323 323 $sqlse = "SELECT MIN($col) FROM $table WHERE $where"; 324 324 } 325 // MIN ʸ¤Î¼Â¹Ô325 // MIN文の実行 326 326 $ret = $this->conn->getOne($sqlse, $arrval); 327 327 return $ret; 328 328 } 329 329 330 // ÆÃÄê¤Î¥«¥é¥à¤ÎÃͤò¼èÆÀ330 // 特定のカラムの値を取得 331 331 function get($table, $col, $where = "", $arrval = array()) { 332 332 if(strlen($where) <= 0) { … … 335 335 $sqlse = "SELECT $col FROM $table WHERE $where"; 336 336 } 337 // SQL ʸ¤Î¼Â¹Ô337 // SQL文の実行 338 338 $ret = $this->conn->getOne($sqlse, $arrval); 339 339 return $ret; … … 341 341 342 342 function getone($sql, $arrval = array()) { 343 // SQL ʸ¤Î¼Â¹Ô343 // SQL文の実行 344 344 $ret = $this->conn->getOne($sql, $arrval); 345 345 return $ret; … … 347 347 } 348 348 349 // °ì¹Ô¤ò¼èÆÀ349 // 一行を取得 350 350 function getrow($table, $col, $where = "", $arrval = array()) { 351 351 if(strlen($where) <= 0) { … … 354 354 $sqlse = "SELECT $col FROM $table WHERE $where"; 355 355 } 356 // SQL ʸ¤Î¼Â¹Ô356 // SQL文の実行 357 357 $ret = $this->conn->getRow($sqlse, $arrval); 358 358 … … 360 360 } 361 361 362 // ¥ì¥³¡¼¥É¤Îºï½ü362 // レコードの削除 363 363 function delete($table, $where = "", $arrval = array()) { 364 364 if(strlen($where) <= 0) { … … 373 373 function nextval($table, $colname) { 374 374 $sql = ""; 375 // postgresql ¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë375 // postgresqlとmysqlとで処理を分ける 376 376 if (DB_TYPE == "pgsql") { 377 377 $seqtable = $table . "_" . $colname . "_seq"; … … 417 417 } 418 418 419 // auto_increment ¤ò¼èÆÀ¤¹¤ë419 // auto_incrementを取得する 420 420 function get_auto_increment($table_name){ 421 // ¥í¥Ã¥¯¤¹¤ë421 // ロックする 422 422 $this->BEGIN(); 423 423 424 // ¼¡¤ÎIncrement¤ò¼èÆÀ424 // 次のIncrementを取得 425 425 $arrRet = $this->getAll("SHOW TABLE STATUS LIKE ?", array($table_name)); 426 426 $auto_inc_no = $arrRet[0]["Auto_increment"]; 427 427 428 // Ãͤò¥«¥¦¥ó¥È¥¢¥Ã¥×¤·¤Æ¤ª¤¯428 // 値をカウントアップしておく 429 429 $this->conn->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1); 430 430 431 // ²ò½ü¤¹¤ë431 // 解除する 432 432 $this->COMMIT(); 433 433
Note: See TracChangeset
for help on using the changeset viewer.
