

Public Member Functions | |
| db_connect () | |
| Non-persistent database connection. | |
| db_pconnect () | |
| Persistent database connection. | |
| db_select () | |
| Select the database. | |
| db_set_charset ($charset, $collation) | |
| Set client character set. | |
| _version () | |
| Version number query string. | |
| _execute ($sql) | |
| Execute the query. | |
| _prep_query ($sql) | |
| Prep the query. | |
| trans_begin ($test_mode=FALSE) | |
| Begin Transaction. | |
| trans_commit () | |
| Commit Transaction. | |
| trans_rollback () | |
| Rollback Transaction. | |
| escape_str ($str) | |
| Escape String. | |
| affected_rows () | |
| Affected Rows. | |
| insert_id () | |
| Insert ID. | |
| count_all ($table= '') | |
| "Count All" query | |
| _list_tables ($prefix_limit=FALSE) | |
| List table query. | |
| _list_columns ($table= '') | |
| Show column query. | |
| _field_data ($table) | |
| Field data query. | |
| _error_message () | |
| The error message string. | |
| _error_number () | |
| The error message number. | |
| _escape_table ($table) | |
| Escape Table Name. | |
| _protect_identifiers ($item, $first_word_only=FALSE) | |
| Protect Identifiers. | |
| _from_tables ($tables) | |
| From Tables. | |
| _insert ($table, $keys, $values) | |
| Insert statement. | |
| _update ($table, $values, $where, $orderby=array(), $limit=FALSE) | |
| Update statement. | |
| _truncate ($table) | |
| Truncate statement. | |
| _delete ($table, $where=array(), $like=array(), $limit=FALSE) | |
| Delete statement. | |
| _limit ($sql, $limit, $offset) | |
| Limit string. | |
| _close ($conn_id) | |
| Close DB Connection. | |
Public Attributes | |
| $_count_string = "SELECT COUNT(*) AS " | |
| The syntax to count rows is slightly different across different database engines, so this string appears in each driver and is used for the count_all() and count_all_results() functions. | |
| $_random_keyword = ' RAND()' | |
| $delete_hack = TRUE | |
| Whether to use the MySQL "delete hack" which allows the number of affected rows to be shown. | |
Definition at line 31 of file mysqli_driver.php.
| CI_DB_mysqli_driver::_close | ( | $ | conn_id | ) |
Close DB Connection.
public
| resource |
Definition at line 640 of file mysqli_driver.php.
| CI_DB_mysqli_driver::_delete | ( | $ | table, | |
| $ | where = array(), |
|||
| $ | like = array(), |
|||
| $ | limit = FALSE | |||
| ) |
Delete statement.
Generates a platform-specific delete string from the supplied data
public
| string | the table name | |
| array | the where clause | |
| string | the limit clause |
Definition at line 585 of file mysqli_driver.php.
00586 { 00587 $conditions = ''; 00588 00589 if (count($where) > 0 OR count($like) > 0) 00590 { 00591 $conditions = "\nWHERE "; 00592 $conditions .= implode("\n", $this->ar_where); 00593 00594 if (count($where) > 0 && count($like) > 0) 00595 { 00596 $conditions .= " AND "; 00597 } 00598 $conditions .= implode("\n", $like); 00599 } 00600 00601 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; 00602 00603 return "DELETE FROM ".$table.$conditions.$limit; 00604 }
| CI_DB_mysqli_driver::_error_message | ( | ) |
| CI_DB_mysqli_driver::_error_number | ( | ) |
| CI_DB_mysqli_driver::_escape_table | ( | $ | table | ) |
Escape Table Name.
This function adds backticks if the table name has a period in it. Some DBs will get cranky unless periods are escaped
private
| string | the table name |
Definition at line 410 of file mysqli_driver.php.
00411 { 00412 if (strpos($table, '.') !== FALSE) 00413 { 00414 $table = '`' . str_replace('.', '`.`', $table) . '`'; 00415 } 00416 00417 return $table; 00418 }
| CI_DB_mysqli_driver::_execute | ( | $ | sql | ) |
Execute the query.
private called by the base class
| string | an SQL query |
Definition at line 124 of file mysqli_driver.php.
References _prep_query().
00125 { 00126 $sql = $this->_prep_query($sql); 00127 $result = @mysqli_query($this->conn_id, $sql); 00128 return $result; 00129 }

| CI_DB_mysqli_driver::_field_data | ( | $ | table | ) |
Field data query.
Generates a platform-specific query so that the column data can be retrieved
public
| string | the table name |
Definition at line 367 of file mysqli_driver.php.
| CI_DB_mysqli_driver::_from_tables | ( | $ | tables | ) |
From Tables.
This function implicitly groups FROM tables so there is no confusion about operator precedence in harmony with SQL standards
public
| type |
Definition at line 492 of file mysqli_driver.php.
00493 { 00494 if ( ! is_array($tables)) 00495 { 00496 $tables = array($tables); 00497 } 00498 00499 return '('.implode(', ', $tables).')'; 00500 }
| CI_DB_mysqli_driver::_insert | ( | $ | table, | |
| $ | keys, | |||
| $ | values | |||
| ) |
Insert statement.
Generates a platform-specific insert string from the supplied data
public
| string | the table name | |
| array | the insert keys | |
| array | the insert values |
Definition at line 515 of file mysqli_driver.php.
00516 { 00517 return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; 00518 }
| CI_DB_mysqli_driver::_limit | ( | $ | sql, | |
| $ | limit, | |||
| $ | offset | |||
| ) |
Limit string.
Generates a platform-specific LIMIT clause
public
| string | the sql query string | |
| integer | the number of rows to limit the query to | |
| integer | the offset value |
Definition at line 619 of file mysqli_driver.php.
00620 { 00621 $sql .= "LIMIT ".$limit; 00622 00623 if ($offset > 0) 00624 { 00625 $sql .= " OFFSET ".$offset; 00626 } 00627 00628 return $sql; 00629 }
| CI_DB_mysqli_driver::_list_columns | ( | $ | table = '' |
) |
Show column query.
Generates a platform-specific query string so that the column names can be fetched
public
| string | the table name |
Definition at line 351 of file mysqli_driver.php.
| CI_DB_mysqli_driver::_list_tables | ( | $ | prefix_limit = FALSE |
) |
List table query.
Generates a platform-specific query string so that the table names can be fetched
private
| boolean |
Definition at line 328 of file mysqli_driver.php.
00329 { 00330 $sql = "SHOW TABLES FROM `".$this->database."`"; 00331 00332 if ($prefix_limit !== FALSE AND $this->dbprefix != '') 00333 { 00334 $sql .= " LIKE '".$this->dbprefix."%'"; 00335 } 00336 00337 return $sql; 00338 }
| CI_DB_mysqli_driver::_prep_query | ( | $ | sql | ) |
Prep the query.
If needed, each database adapter can prep the query string
private called by execute()
| string | an SQL query |
Definition at line 142 of file mysqli_driver.php.
Referenced by _execute().
00143 { 00144 // "DELETE FROM TABLE" returns 0 affected rows This hack modifies 00145 // the query so that it returns the number of affected rows 00146 if ($this->delete_hack === TRUE) 00147 { 00148 if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) 00149 { 00150 $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); 00151 } 00152 } 00153 00154 return $sql; 00155 }

| CI_DB_mysqli_driver::_protect_identifiers | ( | $ | item, | |
| $ | first_word_only = FALSE | |||
| ) |
Protect Identifiers.
This function adds backticks if appropriate based on db type
private
| mixed | the item to escape | |
| boolean | only affect the first word |
Definition at line 432 of file mysqli_driver.php.
Referenced by count_all().
00433 { 00434 if (is_array($item)) 00435 { 00436 $escaped_array = array(); 00437 00438 foreach($item as $k=>$v) 00439 { 00440 $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); 00441 } 00442 00443 return $escaped_array; 00444 } 00445 00446 // This function may get "item1 item2" as a string, and so 00447 // we may need "`item1` `item2`" and not "`item1 item2`" 00448 if (ctype_alnum($item) === FALSE) 00449 { 00450 if (strpos($item, '.') !== FALSE) 00451 { 00452 $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; 00453 $table_name = substr($item, 0, strpos($item, '.')+1); 00454 $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; 00455 } 00456 00457 // This function may get "field >= 1", and need it to return "`field` >= 1" 00458 $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; 00459 00460 $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); 00461 } 00462 else 00463 { 00464 return "`{$item}`"; 00465 } 00466 00467 $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); 00468 00469 foreach ($exceptions as $exception) 00470 { 00471 00472 if (stristr($item, " `{$exception}` ") !== FALSE) 00473 { 00474 $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); 00475 } 00476 } 00477 return $item; 00478 }

| CI_DB_mysqli_driver::_truncate | ( | $ | table | ) |
Truncate statement.
Generates a platform-specific truncate string from the supplied data If the database does not support the truncate() command This function maps to "DELETE FROM table"
public
| string | the table name |
Definition at line 567 of file mysqli_driver.php.
| CI_DB_mysqli_driver::_update | ( | $ | table, | |
| $ | values, | |||
| $ | where, | |||
| $ | orderby = array(), |
|||
| $ | limit = FALSE | |||
| ) |
Update statement.
Generates a platform-specific update string from the supplied data
public
| string | the table name | |
| array | the update data | |
| array | the where clause | |
| array | the orderby clause | |
| array | the limit clause |
Definition at line 535 of file mysqli_driver.php.
00536 { 00537 foreach($values as $key => $val) 00538 { 00539 $valstr[] = $key." = ".$val; 00540 } 00541 00542 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; 00543 00544 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; 00545 00546 $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); 00547 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; 00548 $sql .= $orderby.$limit; 00549 00550 return $sql; 00551 }
| CI_DB_mysqli_driver::_version | ( | ) |
Version number query string.
public
Definition at line 110 of file mysqli_driver.php.
| CI_DB_mysqli_driver::affected_rows | ( | ) |
| CI_DB_mysqli_driver::count_all | ( | $ | table = '' |
) |
"Count All" query
Generates a platform-specific query string that counts all records in the specified database
public
| string |
Definition at line 303 of file mysqli_driver.php.
References _protect_identifiers().
00304 { 00305 if ($table == '') 00306 return '0'; 00307 00308 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); 00309 00310 if ($query->num_rows() == 0) 00311 return '0'; 00312 00313 $row = $query->row(); 00314 return $row->numrows; 00315 }

| CI_DB_mysqli_driver::db_connect | ( | ) |
Non-persistent database connection.
private called by the base class
Definition at line 56 of file mysqli_driver.php.
Referenced by db_pconnect().

| CI_DB_mysqli_driver::db_pconnect | ( | ) |
Persistent database connection.
private called by the base class
Definition at line 69 of file mysqli_driver.php.
References db_connect().
00070 { 00071 return $this->db_connect(); 00072 }

| CI_DB_mysqli_driver::db_select | ( | ) |
Select the database.
private called by the base class
Definition at line 82 of file mysqli_driver.php.
| CI_DB_mysqli_driver::db_set_charset | ( | $ | charset, | |
| $ | collation | |||
| ) |
Set client character set.
public
| string | ||
| string |
Definition at line 97 of file mysqli_driver.php.
References escape_str().
00098 { 00099 return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); 00100 }

| CI_DB_mysqli_driver::escape_str | ( | $ | str | ) |
Escape String.
public
| string |
Definition at line 249 of file mysqli_driver.php.
Referenced by db_set_charset().
00250 { 00251 if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) 00252 { 00253 return mysqli_real_escape_string($this->conn_id, $str); 00254 } 00255 elseif (function_exists('mysql_escape_string')) 00256 { 00257 return mysql_escape_string($str); 00258 } 00259 else 00260 { 00261 return addslashes($str); 00262 } 00263 }

| CI_DB_mysqli_driver::insert_id | ( | ) |
| CI_DB_mysqli_driver::trans_begin | ( | $ | test_mode = FALSE |
) |
Begin Transaction.
public
Definition at line 165 of file mysqli_driver.php.
00166 { 00167 if ( ! $this->trans_enabled) 00168 { 00169 return TRUE; 00170 } 00171 00172 // When transactions are nested we only begin/commit/rollback the outermost ones 00173 if ($this->_trans_depth > 0) 00174 { 00175 return TRUE; 00176 } 00177 00178 // Reset the transaction failure flag. 00179 // If the $test_mode flag is set to TRUE transactions will be rolled back 00180 // even if the queries produce a successful result. 00181 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; 00182 00183 $this->simple_query('SET AUTOCOMMIT=0'); 00184 $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK 00185 return TRUE; 00186 }
| CI_DB_mysqli_driver::trans_commit | ( | ) |
Commit Transaction.
public
Definition at line 196 of file mysqli_driver.php.
00197 { 00198 if ( ! $this->trans_enabled) 00199 { 00200 return TRUE; 00201 } 00202 00203 // When transactions are nested we only begin/commit/rollback the outermost ones 00204 if ($this->_trans_depth > 0) 00205 { 00206 return TRUE; 00207 } 00208 00209 $this->simple_query('COMMIT'); 00210 $this->simple_query('SET AUTOCOMMIT=1'); 00211 return TRUE; 00212 }
| CI_DB_mysqli_driver::trans_rollback | ( | ) |
Rollback Transaction.
public
Definition at line 222 of file mysqli_driver.php.
00223 { 00224 if ( ! $this->trans_enabled) 00225 { 00226 return TRUE; 00227 } 00228 00229 // When transactions are nested we only begin/commit/rollback the outermost ones 00230 if ($this->_trans_depth > 0) 00231 { 00232 return TRUE; 00233 } 00234 00235 $this->simple_query('ROLLBACK'); 00236 $this->simple_query('SET AUTOCOMMIT=1'); 00237 return TRUE; 00238 }
| CI_DB_mysqli_driver::$_count_string = "SELECT COUNT(*) AS " |
The syntax to count rows is slightly different across different database engines, so this string appears in each driver and is used for the count_all() and count_all_results() functions.
Definition at line 38 of file mysqli_driver.php.
| CI_DB_mysqli_driver::$_random_keyword = ' RAND()' |
Definition at line 39 of file mysqli_driver.php.
| CI_DB_mysqli_driver::$delete_hack = TRUE |
Whether to use the MySQL "delete hack" which allows the number of affected rows to be shown.
Uses a preg_replace when enabled, adding a bit more processing to all queries.
Definition at line 46 of file mysqli_driver.php.