Changeset 1555
- Timestamp:
- 12/16/2007 03:57:33 PM (13 months ago)
- Location:
- trunk/system/libraries/drivers
- Files:
-
- 2 modified
-
Database.php (modified) (13 diffs)
-
Database_Mysql.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/drivers/Database.php
r1522 r1555 14 14 15 15 /** 16 * Method: connect 17 * Connects to the database. 18 * 19 * Returns: 20 * Database link on success or FALSE on failure 16 * Connect to our database 17 * Returns FALSE on failure or a MySQL resource 18 * 19 * @return mixed 21 20 */ 22 21 abstract public function connect(); 23 22 24 23 /** 25 * Method: query 26 * Executes a query. 27 * 28 * Parameters: 29 * sql - query to execute 30 * 31 * Returns: 32 * Database result object 24 * Perform a query based on a manually written query 25 * 26 * @param string $sql 27 * @return Mysql_Result 33 28 */ 34 29 abstract public function query($sql); 35 30 36 31 /** 37 * Method: delete 38 * Builds a DELETE query. 39 * 40 * Parameters: 41 * table - table name 42 * where - WHERE clause 43 * 44 * Returns: 45 * A DELETE sql query string 32 * Builds a DELETE query. 33 * 34 * @param string $table 35 * @param array $where 36 * @return string 46 37 */ 47 38 public function delete($table, $where) … … 51 42 52 43 /** 53 * Method: update 54 * Builds an UPDATE query. 55 * 56 * Parameters: 57 * table - table name 58 * values - associative array of values 59 * where - WHERE clause 60 * 61 * Returns: 62 * An UPDATE sql query string 44 * Builds an UPDATE query. 45 * 46 * @param string $table 47 * @param array $values 48 * @param array $where 49 * @return string 63 50 */ 64 51 public function update($table, $values, $where) … … 72 59 73 60 /** 74 * Method: set_charset 75 * Sets the character set for future queries. 76 * 77 * Parameters: 78 * charset - character set 61 * Set the charset using 'SET NAMES <charset>' 62 * 63 * @param string $charset 79 64 */ 80 65 abstract public function set_charset($charset); 81 66 82 67 /** 83 * Method: escape_table 84 * Escape the passed table name. 85 * 86 * Parameters: 87 * table - table name 88 * 89 * Returns: 90 * A string containing the escaped table name 68 * Wrap the tablename in backticks, has support for: table.field syntax. 69 * 70 * @param string $table 71 * @return string 91 72 */ 92 73 abstract public function escape_table($table); 93 74 94 75 /** 95 * Method: escape_column 96 * Escape the passed column name. 97 * 98 * Parameters: 99 * column - column name 100 * 101 * Returns: 102 * A string containing the escaped column name 76 * Escape a column/field name, has support for special commands. 77 * 78 * @param string $column 79 * @return string 103 80 */ 104 81 abstract public function escape_column($column); 105 82 106 83 /** 107 * Method: where 108 * Builds a WHERE portion of a query. 109 * 110 * Parameters: 111 * key - key name or array of key => value pairs 112 * value - value to match with key 113 * type - operator to join multiple wheres with (AND/OR) 114 * num_wheres - number of existing WHERE clauses 115 * quote - disable quoting of WHERE clause 116 * 117 * Returns: 118 * A WHERE portion of a query 84 * Builds a WHERE portion of a query. 85 * 86 * @param mixed $key 87 * @param string $value 88 * @param string $type 89 * @param int $num_wheres 90 * @param bool $quote 91 * @return string 119 92 */ 120 93 public function where($key, $value, $type, $num_wheres, $quote) … … 166 139 167 140 /** 168 * Method: like 169 * Builds a LIKE portion of a query. 170 * 171 * Parameters: 172 * field - field name or array of field => match pairs 173 * match - like value to match with field 174 * type - operator to join multiple likes with (AND/OR) 175 * num_likes - number of existing WHERE clauses 176 * 177 * Returns: 178 * A LIKE portion of a query 141 * Builds a LIKE portion of a query. 142 * 143 * @param mixed $field 144 * @param string $match 145 * @param string $type 146 * @param int $num_likes 147 * @return string 179 148 */ 180 149 public function like($field, $match = '', $type = 'AND ', $num_likes) … … 190 159 191 160 /** 192 * Method: notlike 193 * Builds a NOT LIKE portion of a query. 194 * 195 * Parameters: 196 * field - field name or array of field => match pairs 197 * match - like value to match with field 198 * type - operator to join multiple likes with (AND/OR) 199 * num_likes - number of existing WHERE clauses 200 * 201 * Returns: 202 * A NOT LIKE portion of a query 161 * Builds a NOT LIKE portion of a query. 162 * 163 * @param mixed $field 164 * @param string $match 165 * @param string $type 166 * @param int $num_likes 167 * @return string 203 168 */ 204 169 public function notlike($field, $match = '', $type = 'AND ', $num_likes) … … 214 179 215 180 /** 216 * Method: regex 217 * Builds a REGEXP portion of a query. 218 * 219 * Parameters: 220 * field - field name or array of field => match pairs 221 * match - like value to match with field 222 * type - operator to join multiple likes with (AND/OR) 223 * num_regexs - number of existing WHERE clauses 224 * 225 * Returns: 226 * A string containing the REGEXP query 181 * Builds a REGEX portion of a query 182 * 183 * @param string $field 184 * @param string $match 185 * @param string $type 186 * @param integer $num_regexs 187 * @return string 227 188 */ 228 189 abstract public function regex($field, $match, $type, $num_regexs); 229 190 230 191 /** 231 * Method: notregex 232 * Builds a NOT REGEXP portion of a query. 233 * 234 * Parameters: 235 * field - field name or array of field => match pairs 236 * match - like value to match with field 237 * type - operator to join multiple likes with (AND/OR) 238 * num_regexs - number of existing WHERE clauses 239 * 240 * Returns: 241 * A string containing the NOT REGEXP query 192 * Builds a NOT REGEX portion of a query 193 * 194 * @param string $field 195 * @param string $match 196 * @param string $type 197 * @param integer $num_regexs 198 * @return string 242 199 */ 243 200 abstract public function notregex($field, $match, $type, $num_regexs); 244 201 245 202 /** 246 * Method: insert 247 * Builds an INSERT query. 248 * 249 * Parameters: 250 * table - table name 251 * keys - array of keys 252 * values - array of values for the keys 253 * 254 * Returns: 255 * A string containing the INSERT query 203 * Builds an INSERT query. 204 * 205 * @param string $table 206 * @param array $keys 207 * @param array $values 208 * @return string 256 209 */ 257 210 public function insert($table, $keys, $values) … … 266 219 267 220 /** 268 * Method: merge 269 * Builds an MERGE query. 270 * 271 * Parameters: 272 * table - table name 273 * keys - array of keys 274 * values - array of values for the keys 275 * 276 * Returns: 277 * A string containing the MERGE query 221 * Builds a MERGE portion of a query. 222 * 223 * @param string $table 224 * @param array $keys 225 * @param array $values 226 * @return string 278 227 */ 279 228 abstract public function merge($table, $keys, $values); 280 229 281 230 /** 282 * Method: limit 283 * Builds a LIMIT portion of a query. 284 * 285 * Parameters: 286 * limit - number of rows to limit result to 287 * offset - offset in result to start returning rows from 288 * 289 * Returns: 290 * A string containing the LIMIT query 231 * Builds a LIMIT portion of a query. 232 * 233 * @param integer $limit 234 * @param integer $offset 235 * @return string 291 236 */ 292 237 abstract public function limit($limit, $offset = 0); 293 238 294 239 /** 295 * Method: compile_select296 240 * Compiles the SELECT statement. 297 241 * Generates a query string based on which functions were used. 298 242 * Should not be called directly, the get() function calls it. 299 243 * 300 * Parameters: 301 * database - all the query parts set from the database library 302 * 303 * Returns: 304 * A string containing the SELECT query 244 * @param array $database 245 * @return string 305 246 */ 306 247 abstract public function compile_select($database); 307 248 308 249 /** 309 * Method: has_operator 310 * Determines if the string has an arithmetic operator in it. 311 * 312 * Parameters: 313 * str - string to test 314 * 315 * Returns: 316 * TRUE if the string has an operator in it, FALSE otherwise 250 * Determines if the string has an arithmetic operator in it. 251 * 252 * @param string $str 253 * @return boolean 317 254 */ 318 255 public function has_operator($str) … … 322 259 323 260 /** 324 * Method: escape 325 * Escapes a value for a query. 326 * 327 * Parameters: 328 * value - value to escape 329 * 330 * Returns: 331 * An escaped version of the value 261 * Escapes any input value 262 * 263 * @param mixed $value 264 * @return string 332 265 */ 333 266 public function escape($value) … … 350 283 351 284 /** 352 * Method: escape_str 353 * Escapes a string for a query. 354 * 355 * Parameters: 356 * str - string to escape 357 * 358 * Returns: 359 * An escaped version of the string 285 * Escapes a string for a query 286 * 287 * @param mixed $str but most likely string 288 * @return mixed but most likely string 360 289 */ 361 290 abstract public function escape_str($str); 362 291 363 292 /** 364 * Method: list_tables 365 * List all tables in the database. 366 * 367 * Returns: 368 * An array of table names 293 * Lists all tables in the database 294 * 295 * @return array 369 296 */ 370 297 abstract public function list_tables(); 371 298 372 299 /** 373 * Method: show_error 374 * Shows the last database error. 375 * 376 * Returns: 377 * A string containing the error 300 * Returns the last database error 301 * 302 * @return string 378 303 */ 379 304 abstract public function show_error(); 380 305 381 306 /** 382 * Method: field_data 383 * Returns field data about a table. 384 * 385 * Parameters: 386 * table - table name 387 * 388 * Returns: 389 * An array containing the field data or FALSE if the table doesn't exist. 307 * Returns field data about a table. 308 * 309 * @param string $table 310 * @return array 390 311 */ 391 312 abstract public function field_data($table); … … 393 314 /** 394 315 * Fetches SQL type information about a field, in a generic format. 316 * 317 * @param string $str 318 * @return array 395 319 */ 396 320 protected function sql_type($str) … … 449 373 450 374 /** 451 * Method: clear_cache 452 * Clears the internal query cache 453 * 454 * Parameters: 455 * sql - the sql command to clear, leave blank to clear entire cache 375 * Clears the internal query cache 376 * 377 * @param string $sql 456 378 */ 457 379 public function clear_cache($sql = NULL) … … 473 395 * trims, and hashes. 474 396 * 475 * Returns:476 * SHA1 hash397 * @param string $sql 398 * @return string 477 399 */ 478 400 protected function query_hash($sql) … … 484 406 485 407 /** 486 * Interface: Database_Result 487 * Database Result API driver 408 * Database_Result 488 409 * 489 * Kohana Source Code:490 * author - Kohana Team491 * copyright - (c) 2007 Kohana Team492 * license - <http://kohanaphp.com/license.html>493 410 */ 494 411 interface Database_Result { 495 412 496 413 /** 497 * Method: result 498 * Prepares the query result. 499 * 500 * Parameters: 501 * object - return objects or arrays 502 * type - array type to use (if using arrays) or class name (if using objects) 503 * 504 * Returns: 505 * Database result object 414 * Prepares the query result. 415 * 416 * @param bool $object 417 * @param mixed $type 418 * @return object 506 419 */ 507 420 public function result($object = TRUE, $type = FALSE); 508 421 509 422 /** 510 * Method: result_array 511 * Builds an array of query results. 512 * 513 * Parameters: 514 * object - return objects or arrays 515 * type - array type to use (if using arrays) or class name (if using objects) 516 * 517 * Returns: 518 * Database result object 423 * Builds an array of query results. 424 * 425 * @param bool $object 426 * @param mixed $type 427 * @return array 519 428 */ 520 429 public function result_array($object = NULL, $type = FALSE); 521 430 522 431 /** 523 * Method: insert_id 524 * Gets the id of an INSERT statement. 525 * 526 * Returns: 527 * The insert id number 432 * gets the ID of the last insert statement 433 * 434 * @return int 528 435 */ 529 436 public function insert_id(); 530 437 531 438 /** 532 * Method: list_fields 533 * Gets the fields of an already run query 534 * 535 * Returns: 536 * an array containing the fields 439 * Gets the fields of an already run query 440 * 441 * @return array 537 442 */ 538 443 public function list_fields(); -
trunk/system/libraries/drivers/Database_Mysql.php
r1551 r1555 49 49 } 50 50 51 /**52 * Connect to our database53 * Returns FALSE on failure or a MySQL resource54 *55 * @return mixed56 */57 51 public function connect() 58 52 { … … 81 75 } 82 76 83 /**84 * Perform a query based on a manually written query85 *86 * @param string $sql87 * @return Mysql_Result88 */89 77 public function query($sql) 90 78 { … … 107 95 } 108 96 109 /**110 * Set the charset using 'SET NAMES <charset>'111 *112 * @param string $charset113 */114 97 public function set_charset($charset) 115 98 { … … 117 100 } 118 101 119 /**120 * Wrap the tablename in backticks, has support for: table.field syntax.121 *122 * @param string $table123 * @return string124 */125 102 public function escape_table($table) 126 103 { … … 128 105 } 129 106 130 /**131 * Escape a column/field name, has support for special commands.132 *133 * @param string $column134 * @return string135 */136 107 public function escape_column($column) 137 108 { … … 175 146 } 176 147 177 /**178 * MySQL command 'REGEXP'179 *180 * @param string $field181 * @param string $match182 * @param string $type183 * @param integer $num_regexs184 * @return string185 */186 148 public function regex($field, $match = '', $type = 'AND ', $num_regexs) 187 149 { … … 191 153 } 192 154 193 /**194 * MySQL command 'NOT REGEXP'195 *196 * @param string $field197 * @param string $match198 * @param string $type199 * @param integer $num_regexs200 * @return string201 */202 155 public function notregex($field, $match = '', $type = 'AND ', $num_regexs) 203 156 { … … 207 160 } 208 161 209 /**210 * MySQL command 'REPLACE INTO ..'211 *212 * @param string $table213 * @param array $keys214 * @param array $values215 * @return string216 */217 162 public function merge($table, $keys, $values) 218 163 { … … 225 170 } 226 171 227 /**228 * MySQL command 'LIMIT'229 *230 * @param integer $limit231 * @param integer $offset232 * @return string233 */234 172 public function limit($limit, $offset = 0) 235 173 { … … 237 175 } 238 176 239 /**240 * Compile our select statement into a ready SQL query241 *242 * @param array $database243 * @return string244 */245 177 public function compile_select($database) 246 178 { … … 293 225 } 294 226 295 /**296 * Input escape, using mysql_real_escape_string()297 *298 * @param mixed $str but most likely string299 * @return mixed but most likely string300 */301 227 public function escape_str($str) 302 228 { … … 306 232 } 307 233 308 /**309 * MySQL command 'SHOW TABLES FROM ..'310 *311 * @return array312 */313 234 public function list_tables() 314 235 { … … 325 246 } 326 247 327 /**328 * Return the last error reported by mysql_error()329 *330 * @return string331 */332 248 public function show_error() 333 249 { … … 357 273 } 358 274 359 /**360 * MySQL command 'SHOW COLUMNS FROM ..'361 *362 * @param string $table363 * @return array364 */365 275 public f
