Changeset 13291
- Timestamp:
- 2007/05/22 19:23:21 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/dev/data/class/SC_Query.php
r337 r13291 1 1 <?php 2 /* 2 /** 3 3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. 4 4 * … … 6 6 */ 7 7 8 /** 9 * SC_Query¥¯¥é¥¹ 10 * 11 * @author LOCKON CO.,LTD. 12 * @access public 13 */ 8 14 class SC_Query { 9 var $option; 10 var $where; 11 var $conn; 12 var $groupby; 13 var $order; 14 15 // ¥³¥ó¥¹¥È¥é¥¯¥¿ 16 /* 17 $err_disp:¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤« 18 $new¡§¿·µ¬¤ËÀܳ¤ò¹Ô¤¦¤« 19 */ 20 function SC_Query($dsn = "", $err_disp = true, $new = false) { 21 $this->conn = new SC_DBconn($dsn, $err_disp, $new); 22 $this->where = ""; 23 return $this->conn; 24 } 25 26 // ¥¨¥é¡¼È½Äê 27 function isError() { 28 if(PEAR::isError($this->conn->conn)) { 29 return true; 30 } 31 return false; 32 } 33 34 // COUNTʸ¤Î¼Â¹Ô 35 function count($table, $where = "", $arrval = array()) { 36 if(strlen($where) <= 0) { 37 $sqlse = "SELECT COUNT(*) FROM $table"; 38 } else { 39 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 40 } 41 // ¥«¥¦¥ó¥Èʸ¤Î¼Â¹Ô 42 $ret = $this->conn->getOne($sqlse, $arrval); 43 return $ret; 44 } 45 46 function select($col, $table, $where = "", $arrval = array()){ 47 $sqlse = $this->getsql($col, $table, $where); 48 $ret = $this->conn->getAll($sqlse, $arrval); 49 return $ret; 50 } 51 52 function getLastQuery($disp = true) { 53 $sql = $this->conn->conn->last_query; 54 if($disp) { 55 print($sql.";<br />\n"); 56 } 57 return $sql; 58 } 15 /**#@+ 16 * @access private 17 */ 18 19 /** 20 * SC_DBConn¥ª¥Ö¥¸¥§¥¯¥È 21 * @var object SC_DBConn 22 */ 23 var $conn; 24 25 /** 26 * LIMIT,OFFSET ¶ç 27 * @var string 28 */ 29 var $option; 30 31 /** 32 * WHERE ¶ç 33 * @var string 34 */ 35 var $where; 36 37 /** 38 * GROUP BY ¶ç 39 * @var string 40 */ 41 var $groupby; 42 43 /** 44 * ORDER BY ¶ç 45 * @var string 46 */ 47 var $order; 48 49 /**#@-*/ 50 51 /** 52 * SC_Query¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿ 53 * 54 * @access public 55 * @param string $dsn DSN¾ðÊó 56 * @param boolean $err_disp ¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤«¤É¤¦¤« 57 * @param boolean $new ¿·µ¬¤ËDBÀܳ¤ò¹Ô¤¦¤«¤É¤¦¤« 58 */ 59 function SC_Query($dsn = "", $err_disp = true, $new = false) { 60 $this->conn = new SC_DBconn($dsn, $err_disp, $new); 61 $this->where = ""; 62 $this->option = ""; 63 $this->groupby = ""; 64 return $this->conn; //? 65 } 66 67 /** 68 * DB¥¨¥é¡¼¤ÎȽÄê 69 * 70 * @access public 71 * @return boolean À®¸ù»þ¡§true ¼ºÇÔ»þ¡§false 72 */ 73 function isError() { 74 if(PEAR::isError($this->conn->conn)) { 75 return true; 76 } 77 return false; 78 } 79 80 /** 81 * COUNTʸ¤Î¼Â¹Ô 82 * 83 * @access public 84 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 85 * @param string $where WHERE¶ç 86 * @param array $arrval ¥×¥ì¡¼¥¹¥Û¥ë¥À¤ÎÇÛÎó 87 * @return string ¥ì¥³¡¼¥É·ï¿ô 88 */ 89 function count($table, $where = "", $arrval = array()) { 90 if(strlen($where) <= 0) { 91 $sqlse = "SELECT COUNT(*) FROM $table"; 92 } else { 93 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 94 } 95 // ¥«¥¦¥ó¥Èʸ¤Î¼Â¹Ô 96 $ret = $this->conn->getOne($sqlse, $arrval); 97 return $ret; 98 } 99 100 /** 101 * SELECTʸ¤Î¼Â¹Ô 102 * 103 * @access public 104 * @param string $col ¥«¥é¥à̾ 105 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 106 * @param string $where WHERE¶ç 107 * @param array $arrval ¥×¥ì¡¼¥¹¥Û¥ë¥À¤ÎÇÛÎó 108 * @return array SELECTʸ¤Î¼Â¹Ô·ë²Ì 109 */ 110 function select($col, $table, $where = "", $arrval = array()){ 111 $sqlse = $this->getsql($col, $table, $where); 112 $ret = $this->conn->getAll($sqlse, $arrval); 113 return $ret; 114 } 115 116 /** 117 * ºÇ¸å¤Ë¼Â¹Ô¤·¤¿SQLʸ¤ò¼èÆÀ¤¹¤ë 118 * 119 * @access public 120 * @param boolean $disp SQLʸ¤òprint¤¹¤ë¤«¤É¤¦¤« 121 * @return string $disp==false¤Î¾ì¹ç¡§ºÇ¸å¤Ë¼Â¹Ô¤·¤¿SQLʸ $disp==true¤Î¾ì¹ç¡§¤Ê¤· 122 */ 123 function getLastQuery($disp = true) { 124 $sql = $this->conn->conn->last_query; 125 if($disp) { 126 print($sql.";<br />\n"); 127 } 128 return $sql; 129 } 59 130 60 131 function commit() { … … 105 176 } 106 177 107 function getsql($col, $table, $where) { 108 if($where != "") { 109 // °ú¿ô¤Î$where¤òÍ¥À褷¤Æ¼Â¹Ô¤¹¤ë¡£ 110 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 111 } else { 112 if($this->where != "") { 113 $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option; 114 } else { 115 $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option; 116 } 117 } 118 return $sqlse; 119 } 120 121 function setoption($str) { 122 $this->option = $str; 123 } 124 125 function setlimitoffset($limit, $offset = 0, $return = false) { 126 if (is_numeric($limit) && is_numeric($offset)){ 127 128 $option.= " LIMIT " . $limit; 129 $option.= " OFFSET " . $offset; 130 131 if($return){ 132 return $option; 133 }else{ 134 $this->option.= $option; 135 } 136 } 137 } 178 /** 179 * SELECTʸ¤ò¹½ÃÛ¤¹¤ë 180 * 181 * @access public 182 * @param string $col ¥«¥é¥à̾ 183 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 184 * @param string $where WHERE¶ç 185 * @return string SQLʸ 186 */ 187 function getsql($col, $table, $where="") { 188 if($where != "") { 189 // °ú¿ô¤Î$where¤òÍ¥À褷¤Æ¼Â¹Ô¤¹¤ë¡£ 190 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 191 } else { 192 if($this->where != "") { 193 $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option; 194 } else { 195 $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option; 196 } 197 } 198 return $sqlse; 199 } 200 201 /** 202 * WHERE,GROUPBY,ORDERBY°Ê³°¤Î¥ª¥×¥·¥ç¥Ê¥ë¤Ê¶ç¤ò¥»¥Ã¥È¤¹¤ë 203 * 204 * @access public 205 * @param string $str ¥ª¥×¥·¥ç¥ó¤Ë»ÈÍѤ¹¤ëʸ»úÎó 206 */ 207 function setoption($str) { 208 $this->option = $str; 209 } 210 211 /** 212 * LIMIT¶ç¡¢OFFSET¶ç¤ò¥»¥Ã¥È¤¹¤ë 213 * 214 * @access public 215 * @param string $limit LIMIT¤Î·ï¿ô 216 * @param integer $offset OFFSET¤Î·ï¿ô 217 * @param string $return À¸À®¤·¤¿LIMIT,OFFSET¶ç¤òreturn¤¹¤ë¤«¤É¤¦¤« 218 * @return string À¸À®¤·¤¿LIMIT,OFFSET¶ç 219 */ 220 function setlimitoffset($limit, $offset = 0, $return = false) { 221 if (is_numeric($limit) && is_numeric($offset)){ 222 223 $option.= " LIMIT " . $limit; 224 $option.= " OFFSET " . $offset; 225 226 if($return){ 227 return $option; 228 }else{ 229 $this->option.= $option; 230 } 231 } 232 } 138 233 139 234 function setgroupby($str) {
Note: See TracChangeset
for help on using the changeset viewer.