
Public Member Functions | |
| CI_DB_driver ($params) | |
| Constructor. | |
| initialize ($create_db=FALSE) | |
| Initialize Database Settings. | |
| platform () | |
| The name of the platform in use (mysql, mssql, etc. | |
| version () | |
| Database Version Number. | |
| query ($sql, $binds=FALSE, $return_object=TRUE) | |
| Execute the query. | |
| load_rdriver () | |
| Load the result drivers. | |
| simple_query ($sql) | |
| Simple Query This is a simplified version of the query() function. | |
| trans_off () | |
| Disable Transactions This permits transactions to be disabled at run-time. | |
| trans_strict ($mode=TRUE) | |
| Enable/disable Transaction Strict Mode When strict mode is enabled, if you are running multiple groups of transactions, if one group fails all groups will be rolled back. | |
| trans_start ($test_mode=FALSE) | |
| Start Transaction. | |
| trans_complete () | |
| Complete Transaction. | |
| trans_status () | |
| Lets you retrieve the transaction flag to determine if it has failed. | |
| compile_binds ($sql, $binds) | |
| Compile Bindings. | |
| is_write_type ($sql) | |
| Determines if a query is a "write" type. | |
| elapsed_time ($decimals=6) | |
| Calculate the aggregate query elapsed time. | |
| total_queries () | |
| Returns the total number of queries. | |
| last_query () | |
| Returns the last query that was executed. | |
| protect_identifiers ($item, $first_word_only=FALSE) | |
| Protect Identifiers. | |
| escape ($str) | |
| "Smart" Escape String | |
| primary ($table= '') | |
| Primary. | |
| list_tables ($constrain_by_prefix=FALSE) | |
| Returns an array of table names. | |
| table_exists ($table_name) | |
| Determine if a particular table exists public. | |
| list_fields ($table= '') | |
| Fetch MySQL Field Names. | |
| field_exists ($field_name, $table_name) | |
| Determine if a particular field exists public. | |
| field_names ($table= '') | |
| DEPRECATED - use list_fields(). | |
| field_data ($table= '') | |
| Returns an object with field data. | |
| insert_string ($table, $data) | |
| Generate an insert string. | |
| update_string ($table, $data, $where) | |
| Generate an update string. | |
| _has_operator ($str) | |
| Tests whether the string has an SQL operator. | |
| prep_tablename ($table= '') | |
| Prep the table name - simply adds the table prefix if needed. | |
| call_function ($function) | |
| Enables a native PHP function to be run, using a platform agnostic wrapper. | |
| cache_set_path ($path= '') | |
| Set Cache Directory Path. | |
| cache_on () | |
| Enable Query Caching. | |
| cache_off () | |
| Disable Query Caching. | |
| cache_delete ($segment_one= '', $segment_two= '') | |
| Delete the cache files associated with a particular URI. | |
| cache_delete_all () | |
| Delete All cache files. | |
| _cache_init () | |
| Initialize the Cache Class. | |
| close () | |
| Close DB Connection. | |
| display_error ($error= '', $swap= '', $native=FALSE) | |
| Display an error message. | |
Public Attributes | |
| $username | |
| $password | |
| $hostname | |
| $database | |
| $dbdriver = 'mysql' | |
| $dbprefix = '' | |
| $char_set = 'utf8' | |
| $dbcollat = 'utf8_general_ci' | |
| $autoinit = TRUE | |
| $swap_pre = '' | |
| $port = '' | |
| $pconnect = FALSE | |
| $conn_id = FALSE | |
| $result_id = FALSE | |
| $db_debug = FALSE | |
| $benchmark = 0 | |
| $query_count = 0 | |
| $bind_marker = '?' | |
| $save_queries = TRUE | |
| $queries = array() | |
| $query_times = array() | |
| $data_cache = array() | |
| $trans_enabled = TRUE | |
| $trans_strict = TRUE | |
| $_trans_depth = 0 | |
| $_trans_status = TRUE | |
| $cache_on = FALSE | |
| $cachedir = '' | |
| $cache_autodel = FALSE | |
| $CACHE | |
| $stmt_id | |
| $curs_id | |
| $limit_used | |
Definition at line 31 of file DB_driver.php.
| CI_DB_driver::_cache_init | ( | ) |
Initialize the Cache Class.
private
Definition at line 1138 of file DB_driver.php.
References cache_off().
Referenced by cache_delete(), cache_delete_all(), and query().
01139 { 01140 if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) 01141 { 01142 return TRUE; 01143 } 01144 01145 if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) 01146 { 01147 return $this->cache_off(); 01148 } 01149 01150 $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects 01151 return TRUE; 01152 }


| CI_DB_driver::_has_operator | ( | $ | str | ) |
Tests whether the string has an SQL operator.
private
| string |
Definition at line 983 of file DB_driver.php.
Referenced by CI_DB_active_record::_having(), CI_DB_active_record::_where(), and update_string().
00984 { 00985 $str = trim($str); 00986 if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) 00987 { 00988 return FALSE; 00989 } 00990 00991 return TRUE; 00992 }

| CI_DB_driver::cache_delete | ( | $ | segment_one = '', |
|
| $ | segment_two = '' | |||
| ) |
Delete the cache files associated with a particular URI.
public
Definition at line 1103 of file DB_driver.php.
References _cache_init().
01104 { 01105 if ( ! $this->_cache_init()) 01106 { 01107 return FALSE; 01108 } 01109 return $this->CACHE->delete($segment_one, $segment_two); 01110 }

| CI_DB_driver::cache_delete_all | ( | ) |
Delete All cache files.
public
Definition at line 1120 of file DB_driver.php.
References _cache_init().
01121 { 01122 if ( ! $this->_cache_init()) 01123 { 01124 return FALSE; 01125 } 01126 01127 return $this->CACHE->delete_all(); 01128 }

| CI_DB_driver::cache_off | ( | ) |
Disable Query Caching.
public
Definition at line 1088 of file DB_driver.php.
References cache_on().
Referenced by _cache_init().
01089 { 01090 $this->cache_on = FALSE; 01091 return FALSE; 01092 }


| CI_DB_driver::cache_on | ( | ) |
Enable Query Caching.
public
Definition at line 1074 of file DB_driver.php.
Referenced by cache_off(), and query().
01075 { 01076 $this->cache_on = TRUE; 01077 return TRUE; 01078 }

| CI_DB_driver::cache_set_path | ( | $ | path = '' |
) |
Set Cache Directory Path.
public
| string | the path to the cache directory |
Definition at line 1061 of file DB_driver.php.
| CI_DB_driver::call_function | ( | $ | function | ) |
Enables a native PHP function to be run, using a platform agnostic wrapper.
public
| string | the function name | |
| mixed | any parameters needed by the function |
Definition at line 1027 of file DB_driver.php.
References display_error().
01028 { 01029 $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; 01030 01031 if (FALSE === strpos($driver, $function)) 01032 { 01033 $function = $driver.$function; 01034 } 01035 01036 if ( ! function_exists($function)) 01037 { 01038 if ($this->db_debug) 01039 { 01040 return $this->display_error('db_unsupported_function'); 01041 } 01042 return FALSE; 01043 } 01044 else 01045 { 01046 $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; 01047 01048 return call_user_func_array($function, $args); 01049 } 01050 }

| CI_DB_driver::CI_DB_driver | ( | $ | params | ) |
Constructor.
Accepts one parameter containing the database connection settings.
| array |
Definition at line 78 of file DB_driver.php.
References log_message().
00079 { 00080 if (is_array($params)) 00081 { 00082 foreach ($params as $key => $val) 00083 { 00084 $this->$key = $val; 00085 } 00086 } 00087 00088 log_message('debug', 'Database Driver Class Initialized'); 00089 }

| CI_DB_driver::close | ( | ) |
Close DB Connection.
public
Definition at line 1162 of file DB_driver.php.
01163 { 01164 if (is_resource($this->conn_id) OR is_object($this->conn_id)) 01165 { 01166 $this->_close($this->conn_id); 01167 } 01168 $this->conn_id = FALSE; 01169 }
| CI_DB_driver::compile_binds | ( | $ | sql, | |
| $ | binds | |||
| ) |
Compile Bindings.
public
| string | the sql statement | |
| array | an array of bind data |
Definition at line 577 of file DB_driver.php.
References escape().
Referenced by query().
00578 { 00579 if (strpos($sql, $this->bind_marker) === FALSE) 00580 { 00581 return $sql; 00582 } 00583 00584 if ( ! is_array($binds)) 00585 { 00586 $binds = array($binds); 00587 } 00588 00589 // Get the sql segments around the bind markers 00590 $segments = explode($this->bind_marker, $sql); 00591 00592 // The count of bind should be 1 less then the count of segments 00593 // If there are more bind arguments trim it down 00594 if (count($binds) >= count($segments)) { 00595 $binds = array_slice($binds, 0, count($segments)-1); 00596 } 00597 00598 // Construct the binded query 00599 $result = $segments[0]; 00600 $i = 0; 00601 foreach ($binds as $bind) 00602 { 00603 $result .= $this->escape($bind); 00604 $result .= $segments[++$i]; 00605 } 00606 00607 return $result; 00608 }


| CI_DB_driver::display_error | ( | $ | error = '', |
|
| $ | swap = '', |
|||
| $ | native = FALSE | |||
| ) |
Display an error message.
public
| string | the error message | |
| string | any "swap" values | |
| boolean | whether to localize the message |
Definition at line 1182 of file DB_driver.php.
References $LANG, and load_class().
Referenced by call_function(), CI_DB_active_record::dbprefix(), CI_DB_active_record::delete(), CI_DB_active_record::empty_table(), field_data(), initialize(), CI_DB_active_record::insert(), list_fields(), list_tables(), query(), CI_DB_active_record::select_avg(), CI_DB_active_record::select_max(), CI_DB_active_record::select_min(), CI_DB_active_record::select_sum(), CI_DB_active_record::truncate(), CI_DB_active_record::update(), and version().
01183 { 01184 global $LANG; 01185 $LANG->load('db'); 01186 01187 $heading = $LANG->line('db_error_heading'); 01188 01189 if ($native == TRUE) 01190 { 01191 $message = $error; 01192 } 01193 else 01194 { 01195 $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; 01196 } 01197 01198 $error =& load_class('Exceptions'); 01199 echo $error->show_error($heading, $message, 'error_db'); 01200 exit; 01201 }


| CI_DB_driver::elapsed_time | ( | $ | decimals = 6 |
) |
Calculate the aggregate query elapsed time.
public
| integer | The number of decimal places |
Definition at line 637 of file DB_driver.php.
| CI_DB_driver::escape | ( | $ | str | ) |
"Smart" Escape String
Escapes data based on type Sets boolean and null types
public
| string |
Definition at line 697 of file DB_driver.php.
Referenced by CI_DB_active_record::_where_in(), compile_binds(), insert_string(), CI_DB_active_record::set(), and update_string().
00698 { 00699 switch (gettype($str)) 00700 { 00701 case 'string' : $str = "'".$this->escape_str($str)."'"; 00702 break; 00703 case 'boolean' : $str = ($str === FALSE) ? 0 : 1; 00704 break; 00705 default : $str = ($str === NULL) ? 'NULL' : $str; 00706 break; 00707 } 00708 00709 return $str; 00710 }

| CI_DB_driver::field_data | ( | $ | table = '' |
) |
Returns an object with field data.
public
| string | the table name |
Definition at line 882 of file DB_driver.php.
References display_error(), prep_tablename(), and query().
00883 { 00884 if ($table == '') 00885 { 00886 if ($this->db_debug) 00887 { 00888 return $this->display_error('db_field_param_missing'); 00889 } 00890 return FALSE; 00891 } 00892 00893 $query = $this->query($this->_field_data($this->prep_tablename($table))); 00894 return $query->field_data(); 00895 }

| CI_DB_driver::field_exists | ( | $ | field_name, | |
| $ | table_name | |||
| ) |
Determine if a particular field exists public.
| string | ||
| string |
Definition at line 858 of file DB_driver.php.
References list_fields().
00859 { 00860 return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; 00861 }

| CI_DB_driver::field_names | ( | $ | table = '' |
) |
DEPRECATED - use list_fields().
Definition at line 868 of file DB_driver.php.
References list_fields().
00869 { 00870 return $this->list_fields($table); 00871 }

| CI_DB_driver::initialize | ( | $ | create_db = FALSE |
) |
Initialize Database Settings.
private Called by the constructor
| mixed |
Definition at line 100 of file DB_driver.php.
References $CI, display_error(), get_instance(), and log_message().
Referenced by simple_query().
00101 { 00102 // If an existing DB connection resource is supplied 00103 // there is no need to connect and select the database 00104 if (is_resource($this->conn_id) OR is_object($this->conn_id)) 00105 { 00106 return TRUE; 00107 } 00108 00109 // Connect to the database 00110 $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); 00111 00112 // No connection? Throw an error 00113 if ( ! $this->conn_id) 00114 { 00115 log_message('error', 'Unable to connect to the database'); 00116 00117 if ($this->db_debug) 00118 { 00119 $this->display_error('db_unable_to_connect'); 00120 } 00121 return FALSE; 00122 } 00123 00124 // Select the database 00125 if ($this->database != '') 00126 { 00127 if ( ! $this->db_select()) 00128 { 00129 // Should we attempt to create the database? 00130 if ($create_db == TRUE) 00131 { 00132 // Load the DB utility class 00133 $CI =& get_instance(); 00134 $CI->load->dbutil(); 00135 00136 // Create the DB 00137 if ( ! $CI->dbutil->create_database($this->database)) 00138 { 00139 log_message('error', 'Unable to create database: '.$this->database); 00140 00141 if ($this->db_debug) 00142 { 00143 $this->display_error('db_unable_to_create', $this->database); 00144 } 00145 return FALSE; 00146 } 00147 else 00148 { 00149 // In the event the DB was created we need to select it 00150 if ($this->db_select()) 00151 { 00152 if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) 00153 { 00154 log_message('error', 'Unable to set database connection charset: '.$this->char_set); 00155 00156 if ($this->db_debug) 00157 { 00158 $this->display_error('db_unable_to_set_charset', $this->char_set); 00159 } 00160 00161 return FALSE; 00162 } 00163 00164 return TRUE; 00165 } 00166 } 00167 } 00168 00169 log_message('error', 'Unable to select database: '.$this->database); 00170 00171 if ($this->db_debug) 00172 { 00173 $this->display_error('db_unable_to_select', $this->database); 00174 } 00175 return FALSE; 00176 } 00177 00178 if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) 00179 { 00180 log_message('error', 'Unable to set database connection charset: '.$this->char_set); 00181 00182 if ($this->db_debug) 00183 { 00184 $this->display_error('db_unable_to_set_charset', $this->char_set); 00185 } 00186 00187 return FALSE; 00188 } 00189 } 00190 00191 return TRUE; 00192 }


| CI_DB_driver::insert_string | ( | $ | table, | |
| $ | data | |||
| ) |
Generate an insert string.
public
| string | the table upon which the query will be performed | |
| array | an associative array data of key/values |
Definition at line 907 of file DB_driver.php.
References escape(), and prep_tablename().
00908 { 00909 $fields = array(); 00910 $values = array(); 00911 00912 foreach($data as $key => $val) 00913 { 00914 $fields[] = $key; 00915 $values[] = $this->escape($val); 00916 } 00917 00918 00919 return $this->_insert($this->prep_tablename($table), $fields, $values); 00920 }

| CI_DB_driver::is_write_type | ( | $ | sql | ) |
Determines if a query is a "write" type.
public
| string | An SQL query string |
Definition at line 619 of file DB_driver.php.
Referenced by query().
00620 { 00621 if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) 00622 { 00623 return FALSE; 00624 } 00625 return TRUE; 00626 }

| CI_DB_driver::last_query | ( | ) |
Returns the last query that was executed.
public
Definition at line 663 of file DB_driver.php.
| CI_DB_driver::list_fields | ( | $ | table = '' |
) |
Fetch MySQL Field Names.
public
| string | the table name |
Definition at line 804 of file DB_driver.php.
References display_error(), prep_tablename(), and query().
Referenced by field_exists(), field_names(), and primary().
00805 { 00806 // Is there a cached result? 00807 if (isset($this->data_cache['field_names'][$table])) 00808 { 00809 return $this->data_cache['field_names'][$table]; 00810 } 00811 00812 if ($table == '') 00813 { 00814 if ($this->db_debug) 00815 { 00816 return $this->display_error('db_field_param_missing'); 00817 } 00818 return FALSE; 00819 } 00820 00821 if (FALSE === ($sql = $this->_list_columns($this->prep_tablename($table)))) 00822 { 00823 if ($this->db_debug) 00824 { 00825 return $this->display_error('db_unsupported_function'); 00826 } 00827 return FALSE; 00828 } 00829 00830 $query = $this->query($sql); 00831 00832 $retval = array(); 00833 foreach($query->result_array() as $row) 00834 { 00835 if (isset($row['COLUMN_NAME'])) 00836 { 00837 $retval[] = $row['COLUMN_NAME']; 00838 } 00839 else 00840 { 00841 $retval[] = current($row); 00842 } 00843 } 00844 00845 $this->data_cache['field_names'][$table] = $retval; 00846 return $this->data_cache['field_names'][$table]; 00847 }


| CI_DB_driver::list_tables | ( | $ | constrain_by_prefix = FALSE |
) |
Returns an array of table names.
public
Definition at line 744 of file DB_driver.php.
References display_error(), and query().
Referenced by table_exists().
00745 { 00746 // Is there a cached result? 00747 if (isset($this->data_cache['table_names'])) 00748 { 00749 return $this->data_cache['table_names']; 00750 } 00751 00752 if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) 00753 { 00754 if ($this->db_debug) 00755 { 00756 return $this->display_error('db_unsupported_function'); 00757 } 00758 return FALSE; 00759 } 00760 00761 $retval = array(); 00762 $query = $this->query($sql); 00763 00764 if ($query->num_rows() > 0) 00765 { 00766 foreach($query->result_array() as $row) 00767 { 00768 if (isset($row['TABLE_NAME'])) 00769 { 00770 $retval[] = $row['TABLE_NAME']; 00771 } 00772 else 00773 { 00774 $retval[] = array_shift($row); 00775 } 00776 } 00777 } 00778 00779 $this->data_cache['table_names'] = $retval; 00780 return $this->data_cache['table_names']; 00781 }


| CI_DB_driver::load_rdriver | ( | ) |
Load the result drivers.
public
Definition at line 420 of file DB_driver.php.
Referenced by query().
00421 { 00422 $driver = 'CI_DB_'.$this->dbdriver.'_result'; 00423 00424 if ( ! class_exists($driver)) 00425 { 00426 include_once(BASEPATH.'database/DB_result'.EXT); 00427 include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); 00428 } 00429 00430 return $driver; 00431 }

| CI_DB_driver::platform | ( | ) |
The name of the platform in use (mysql, mssql, etc.
..)
public
Definition at line 202 of file DB_driver.php.
| CI_DB_driver::prep_tablename | ( | $ | table = '' |
) |
Prep the table name - simply adds the table prefix if needed.
public
| string | the table name |
Definition at line 1003 of file DB_driver.php.
Referenced by field_data(), insert_string(), list_fields(), table_exists(), and update_string().
01004 { 01005 // Do we need to add the table prefix? 01006 if ($this->dbprefix != '') 01007 { 01008 if (substr($table, 0, strlen($this->dbprefix)) != $this->dbprefix) 01009 { 01010 $table = $this->dbprefix.$table; 01011 } 01012 } 01013 01014 return $table; 01015 }

| CI_DB_driver::primary | ( | $ | table = '' |
) |
Primary.
Retrieves the primary key. It assumes that the row in the first position is the primary key
public
| string | the table name |
Definition at line 724 of file DB_driver.php.
References list_fields().
00725 { 00726 $fields = $this->list_fields($table); 00727 00728 if ( ! is_array($fields)) 00729 { 00730 return FALSE; 00731 } 00732 00733 return current($fields); 00734 }

| CI_DB_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 680 of file DB_driver.php.
| CI_DB_driver::query | ( | $ | sql, | |
| $ | binds = FALSE, |
|||
| $ | return_object = TRUE | |||
| ) |
Execute the query.
Accepts an SQL string as input and returns a result object upon successful execution of a "read" type query. Returns boolean TRUE upon successful execution of a "write" type query. Returns boolean FALSE upon failure, and if the $db_debug variable is set to TRUE will raise an error.
public
| string | An SQL query string | |
| array | An array of binding data |
Definition at line 252 of file DB_driver.php.
References _cache_init(), cache_on(), compile_binds(), display_error(), is_write_type(), load_rdriver(), log_message(), simple_query(), and trans_complete().
Referenced by CI_DB_active_record::count_all_results(), CI_DB_active_record::delete(), CI_DB_active_record::empty_table(), field_data(), CI_DB_active_record::get(), CI_DB_active_record::get_where(), CI_DB_active_record::insert(), list_fields(), list_tables(), CI_DB_active_record::truncate(), CI_DB_active_record::update(), and version().
00253 { 00254 if ($sql == '') 00255 { 00256 if ($this->db_debug) 00257 { 00258 log_message('error', 'Invalid query: '.$sql); 00259 return $this->display_error('db_invalid_query'); 00260 } 00261 return FALSE; 00262 } 00263 00264 // Verify table prefix and replace if necessary 00265 if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) 00266 { 00267 $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); 00268 } 00269 00270 // Is query caching enabled? If the query is a "read type" 00271 // we will load the caching class and return the previously 00272 // cached query if it exists 00273 if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) 00274 { 00275 if ($this->_cache_init()) 00276 { 00277 $this->load_rdriver(); 00278 if (FALSE !== ($cache = $this->CACHE->read($sql))) 00279 { 00280 return $cache; 00281 } 00282 } 00283 } 00284 00285 // Compile binds if needed 00286 if ($binds !== FALSE) 00287 { 00288 $sql = $this->compile_binds($sql, $binds); 00289 } 00290 00291 // Save the query for debugging 00292 if ($this->save_queries == TRUE) 00293 { 00294 $this->queries[] = $sql; 00295 } 00296 00297 // Start the Query Timer 00298 $time_start = list($sm, $ss) = explode(' ', microtime()); 00299 00300 // Run the Query 00301 if (FALSE === ($this->result_id = $this->simple_query($sql))) 00302 { 00303 if ($this->save_queries == TRUE) 00304 { 00305 $this->query_times[] = 0; 00306 } 00307 00308 // This will trigger a rollback if transactions are being used 00309 $this->_trans_status = FALSE; 00310 00311 if ($this->db_debug) 00312 { 00313 // grab the error number and message now, as we might run some 00314 // additional queries before displaying the error 00315 $error_no = $this->_error_number(); 00316 $error_msg = $this->_error_message(); 00317 00318 // We call this function in order to roll-back queries 00319 // if transactions are enabled. If we don't call this here 00320 // the error message will trigger an exit, causing the 00321 // transactions to remain in limbo. 00322 $this->trans_complete(); 00323 00324 // Log and display errors 00325 log_message('error', 'Query error: '.$this->_error_message()); 00326 return $this->display_error( 00327 array( 00328 'Error Number: '.$error_no, 00329 $error_msg, 00330 $sql 00331 ) 00332 ); 00333 } 00334 00335 return FALSE; 00336 } 00337 00338 // Stop and aggregate the query time results 00339 $time_end = list($em, $es) = explode(' ', microtime()); 00340 $this->benchmark += ($em + $es) - ($sm + $ss); 00341 00342 if ($this->save_queries == TRUE) 00343 { 00344 $this->query_times[] = ($em + $es) - ($sm + $ss); 00345 } 00346 00347 // Increment the query counter 00348 $this->query_count++; 00349 00350 // Was the query a "write" type? 00351 // If so we'll simply return true 00352 if ($this->is_write_type($sql) === TRUE) 00353 { 00354 // If caching is enabled we'll auto-cleanup any 00355 // existing files related to this particular URI 00356 if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) 00357 { 00358 $this->CACHE->delete(); 00359 } 00360 00361 return TRUE; 00362 } 00363 00364 // Return TRUE if we don't need to create a result object 00365 // Currently only the Oracle driver uses this when stored 00366 // procedures are used 00367 if ($return_object !== TRUE) 00368 { 00369 return TRUE; 00370 } 00371 00372 // Load and instantiate the result driver 00373 00374 $driver = $this->load_rdriver(); 00375 $RES = new $driver(); 00376 $RES->conn_id = $this->conn_id; 00377 $RES->result_id = $this->result_id; 00378 $RES->num_rows = $RES->num_rows(); 00379 00380 if ($this->dbdriver == 'oci8') 00381 { 00382 $RES->stmt_id = $this->stmt_id; 00383 $RES->curs_id = NULL; 00384 $RES->limit_used = $this->limit_used; 00385 } 00386 00387 // Is query caching enabled? If so, we'll serialize the 00388 // result object and save it to a cache file. 00389 if ($this->cache_on == TRUE AND $this->_cache_init()) 00390 { 00391 // We'll create a new instance of the result object 00392 // only without the platform specific driver since 00393 // we can't use it with cached data (the query result 00394 // resource ID won't be any good once we've cached the 00395 // result object, so we'll have to compile the data 00396 // and save it) 00397 $CR = new CI_DB_result(); 00398 $CR->num_rows = $RES->num_rows(); 00399 $CR->result_object = $RES->result_object(); 00400 $CR->result_array = $RES->result_array(); 00401 00402 // Reset these since cached objects can not utilize resource IDs. 00403 $CR->conn_id = NULL; 00404 $CR->result_id = NULL; 00405 00406 $this->CACHE->write($sql, $CR); 00407 } 00408 00409 return $RES; 00410 }


| CI_DB_driver::simple_query | ( | $ | sql | ) |
Simple Query This is a simplified version of the query() function.
Internally we only use it when running transaction commands since they do not require all the features of the main query() function.
public
| string | the sql query |
Definition at line 445 of file DB_driver.php.
References initialize().
Referenced by query().
00446 { 00447 if ( ! $this->conn_id) 00448 { 00449 $this->initialize(); 00450 } 00451 00452 return $this->_execute($sql); 00453 }


| CI_DB_driver::table_exists | ( | $ | table_name | ) |
Determine if a particular table exists public.
Definition at line 790 of file DB_driver.php.
References list_tables(), and prep_tablename().
00791 { 00792 return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; 00793 }

| CI_DB_driver::total_queries | ( | ) |
Returns the total number of queries.
public
Definition at line 650 of file DB_driver.php.
| CI_DB_driver::trans_complete | ( | ) |
Complete Transaction.
public
Definition at line 519 of file DB_driver.php.
References log_message(), and trans_strict().
Referenced by query().
00520 { 00521 if ( ! $this->trans_enabled) 00522 { 00523 return FALSE; 00524 } 00525 00526 // When transactions are nested we only begin/commit/rollback the outermost ones 00527 if ($this->_trans_depth > 1) 00528 { 00529 $this->_trans_depth -= 1; 00530 return TRUE; 00531 } 00532 00533 // The query() function will set this flag to FALSE in the event that a query failed 00534 if ($this->_trans_status === FALSE) 00535 { 00536 $this->trans_rollback(); 00537 00538 // If we are NOT running in strict mode, we will reset 00539 // the _trans_status flag so that subsequent groups of transactions 00540 // will be permitted. 00541 if ($this->trans_strict === FALSE) 00542 { 00543 $this->_trans_status = TRUE; 00544 } 00545 00546 log_message('debug', 'DB Transaction Failure'); 00547 return FALSE; 00548 } 00549 00550 $this->trans_commit(); 00551 return TRUE; 00552 }


| CI_DB_driver::trans_off | ( | ) |
Disable Transactions This permits transactions to be disabled at run-time.
public
Definition at line 464 of file DB_driver.php.
| CI_DB_driver::trans_start | ( | $ | test_mode = FALSE |
) |
Start Transaction.
public
Definition at line 494 of file DB_driver.php.
00495 { 00496 if ( ! $this->trans_enabled) 00497 { 00498 return FALSE; 00499 } 00500 00501 // When transactions are nested we only begin/commit/rollback the outermost ones 00502 if ($this->_trans_depth > 0) 00503 { 00504 $this->_trans_depth += 1; 00505 return; 00506 } 00507 00508 $this->trans_begin($test_mode); 00509 }
| CI_DB_driver::trans_status | ( | ) |
Lets you retrieve the transaction flag to determine if it has failed.
public
Definition at line 562 of file DB_driver.php.
| CI_DB_driver::trans_strict | ( | $ | mode = TRUE |
) |
Enable/disable Transaction Strict Mode When strict mode is enabled, if you are running multiple groups of transactions, if one group fails all groups will be rolled back.
If strict mode is disabled, each group is treated autonomously, meaning a failure of one group will not affect any others
public
Definition at line 481 of file DB_driver.php.
Referenced by trans_complete().
00482 { 00483 $this->trans_strict = is_bool($mode) ? $mode : TRUE; 00484 }

| CI_DB_driver::update_string | ( | $ | table, | |
| $ | data, | |||
| $ | where | |||
| ) |
Generate an update string.
public
| string | the table upon which the query will be performed | |
| array | an associative array data of key/values | |
| mixed | the "where" statement |
Definition at line 933 of file DB_driver.php.
References _has_operator(), escape(), and prep_tablename().
00934 { 00935 if ($where == '') 00936 { 00937 return false; 00938 } 00939 00940 $fields = array(); 00941 foreach($data as $key => $val) 00942 { 00943 $fields[$key] = $this->escape($val); 00944 } 00945 00946 if ( ! is_array($where)) 00947 { 00948 $dest = array($where); 00949 } 00950 else 00951 { 00952 $dest = array(); 00953 foreach ($where as $key => $val) 00954 { 00955 $prefix = (count($dest) == 0) ? '' : ' AND '; 00956 00957 if ($val !== '') 00958 { 00959 if ( ! $this->_has_operator($key)) 00960 { 00961 $key .= ' ='; 00962 } 00963 00964 $val = ' '.$this->escape($val); 00965 } 00966 00967 $dest[] = $prefix.$key.$val; 00968 } 00969 } 00970 00971 return $this->_update($this->prep_tablename($table), $fields, $dest); 00972 }

| CI_DB_driver::version | ( | ) |
Database Version Number.
Returns a string containing the version of the database being used
public
Definition at line 216 of file DB_driver.php.
References display_error(), and query().
00217 { 00218 if (FALSE === ($sql = $this->_version())) 00219 { 00220 if ($this->db_debug) 00221 { 00222 return $this->display_error('db_unsupported_function'); 00223 } 00224 return FALSE; 00225 } 00226 00227 if ($this->dbdriver == 'oci8') 00228 { 00229 return $sql; 00230 } 00231 00232 $query = $this->query($sql); 00233 return $query->row('ver'); 00234 }

| CI_DB_driver::$_trans_depth = 0 |
Definition at line 57 of file DB_driver.php.
| CI_DB_driver::$_trans_status = TRUE |
Definition at line 58 of file DB_driver.php.
| CI_DB_driver::$autoinit = TRUE |
Definition at line 41 of file DB_driver.php.
| CI_DB_driver::$benchmark = 0 |
Definition at line 48 of file DB_driver.php.
| CI_DB_driver::$bind_marker = '?' |
Definition at line 50 of file DB_driver.php.
| CI_DB_driver::$CACHE |
Definition at line 62 of file DB_driver.php.
| CI_DB_driver::$cache_autodel = FALSE |
Definition at line 61 of file DB_driver.php.
| CI_DB_driver::$cache_on = FALSE |
Definition at line 59 of file DB_driver.php.
| CI_DB_driver::$cachedir = '' |
Definition at line 60 of file DB_driver.php.
| CI_DB_driver::$char_set = 'utf8' |
Definition at line 39 of file DB_driver.php.
| CI_DB_driver::$conn_id = FALSE |
Definition at line 45 of file DB_driver.php.
| CI_DB_driver::$curs_id |
Definition at line 67 of file DB_driver.php.
| CI_DB_driver::$data_cache = array() |
Definition at line 54 of file DB_driver.php.
| CI_DB_driver::$database |
Definition at line 36 of file DB_driver.php.
| CI_DB_driver::$db_debug = FALSE |
Definition at line 47 of file DB_driver.php.
| CI_DB_driver::$dbcollat = 'utf8_general_ci' |
Definition at line 40 of file DB_driver.php.
| CI_DB_driver::$dbdriver = 'mysql' |
Definition at line 37 of file DB_driver.php.
| CI_DB_driver::$dbprefix = '' |
Definition at line 38 of file DB_driver.php.
| CI_DB_driver::$hostname |
Definition at line 35 of file DB_driver.php.
| CI_DB_driver::$limit_used |
Definition at line 68 of file DB_driver.php.
| CI_DB_driver::$password |
Definition at line 34 of file DB_driver.php.
| CI_DB_driver::$pconnect = FALSE |
Definition at line 44 of file DB_driver.php.
| CI_DB_driver::$port = '' |
Definition at line 43 of file DB_driver.php.
| CI_DB_driver::$queries = array() |
Definition at line 52 of file DB_driver.php.
| CI_DB_driver::$query_count = 0 |
Definition at line 49 of file DB_driver.php.
| CI_DB_driver::$query_times = array() |
Definition at line 53 of file DB_driver.php.
| CI_DB_driver::$result_id = FALSE |
Definition at line 46 of file DB_driver.php.
| CI_DB_driver::$save_queries = TRUE |
Definition at line 51 of file DB_driver.php.
| CI_DB_driver::$stmt_id |
Definition at line 66 of file DB_driver.php.
| CI_DB_driver::$swap_pre = '' |
Definition at line 42 of file DB_driver.php.
| CI_DB_driver::$trans_enabled = TRUE |
Definition at line 55 of file DB_driver.php.
| CI_DB_driver::$trans_strict = TRUE |
Definition at line 56 of file DB_driver.php.
| CI_DB_driver::$username |
Definition at line 33 of file DB_driver.php.