code
stringlengths
17
296k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public function field_data() { return array(); }
Field data Generates an array of objects containing field meta-data. Overridden by driver result classes. @return array
field_data
php
ronknight/InventorySystem
system/database/DB_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_result.php
MIT
public function free_result() { $this->result_id = FALSE; }
Free the result Overridden by driver result classes. @return void
free_result
php
ronknight/InventorySystem
system/database/DB_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_result.php
MIT
public function data_seek($n = 0) { return FALSE; }
Data Seek Moves the internal pointer to the desired offset. We call this internally before fetching results to make sure the result set starts at zero. Overridden by driver result classes. @param int $n @return bool
data_seek
php
ronknight/InventorySystem
system/database/DB_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_result.php
MIT
protected function _fetch_assoc() { return array(); }
Result - associative array Returns the result set as an array. Overridden by driver result classes. @return array
_fetch_assoc
php
ronknight/InventorySystem
system/database/DB_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_result.php
MIT
protected function _fetch_object($class_name = 'stdClass') { return new $class_name(); }
Result - object Returns the result set as an object. Overridden by driver result classes. @param string $class_name @return object
_fetch_object
php
ronknight/InventorySystem
system/database/DB_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_result.php
MIT
public function select_max($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MAX'); }
Select Max Generates a SELECT MAX(field) portion of a query @param string the field @param string an alias @return CI_DB_query_builder
select_max
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function select_min($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MIN'); }
Select Min Generates a SELECT MIN(field) portion of a query @param string the field @param string an alias @return CI_DB_query_builder
select_min
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function select_avg($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'AVG'); }
Select Average Generates a SELECT AVG(field) portion of a query @param string the field @param string an alias @return CI_DB_query_builder
select_avg
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function select_sum($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'SUM'); }
Select Sum Generates a SELECT SUM(field) portion of a query @param string the field @param string an alias @return CI_DB_query_builder
select_sum
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _create_alias_from_table($item) { if (strpos($item, '.') !== FALSE) { $item = explode('.', $item); return end($item); } return $item; }
Determines the alias name based on the table @param string $item @return string
_create_alias_from_table
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function distinct($val = TRUE) { $this->qb_distinct = is_bool($val) ? $val : TRUE; return $this; }
DISTINCT Sets a flag which tells the query string compiler to add DISTINCT @param bool $val @return CI_DB_query_builder
distinct
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function join($table, $cond, $type = '', $escape = NULL) { if ($type !== '') { $type = strtoupper(trim($type)); if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } else { $type .= ' '; } } // Extract any aliases that might exist. We use this information // in the protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); is_bool($escape) OR $escape = $this->_protect_identifiers; if ( ! $this->_has_operator($cond)) { $cond = ' USING ('.($escape ? $this->escape_identifiers($cond) : $cond).')'; }
JOIN Generates the JOIN portion of the query @param string @param string the join condition @param string the type of join @param string whether not to try to escape identifiers @return CI_DB_query_builder
join
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function where($key, $value = NULL, $escape = NULL) { return $this->_wh('qb_where', $key, $value, 'AND ', $escape); }
WHERE Generates the WHERE portion of the query. Separates multiple calls with 'AND'. @param mixed @param mixed @param bool @return CI_DB_query_builder
where
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_where($key, $value = NULL, $escape = NULL) { return $this->_wh('qb_where', $key, $value, 'OR ', $escape); }
OR WHERE Generates the WHERE portion of the query. Separates multiple calls with 'OR'. @param mixed @param mixed @param bool @return CI_DB_query_builder
or_where
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function where_in($key = NULL, $values = NULL, $escape = NULL) { return $this->_where_in($key, $values, FALSE, 'AND ', $escape); }
WHERE IN Generates a WHERE field IN('item', 'item') SQL query, joined with 'AND' if appropriate. @param string $key The field to search @param array $values The values searched on @param bool $escape @return CI_DB_query_builder
where_in
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_where_in($key = NULL, $values = NULL, $escape = NULL) { return $this->_where_in($key, $values, FALSE, 'OR ', $escape); }
OR WHERE IN Generates a WHERE field IN('item', 'item') SQL query, joined with 'OR' if appropriate. @param string $key The field to search @param array $values The values searched on @param bool $escape @return CI_DB_query_builder
or_where_in
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function where_not_in($key = NULL, $values = NULL, $escape = NULL) { return $this->_where_in($key, $values, TRUE, 'AND ', $escape); }
WHERE NOT IN Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate. @param string $key The field to search @param array $values The values searched on @param bool $escape @return CI_DB_query_builder
where_not_in
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL) { return $this->_where_in($key, $values, TRUE, 'OR ', $escape); }
OR WHERE NOT IN Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate. @param string $key The field to search @param array $values The values searched on @param bool $escape @return CI_DB_query_builder
or_where_not_in
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function like($field, $match = '', $side = 'both', $escape = NULL) { return $this->_like($field, $match, 'AND ', $side, '', $escape); }
LIKE Generates a %LIKE% portion of the query. Separates multiple calls with 'AND'. @param mixed $field @param string $match @param string $side @param bool $escape @return CI_DB_query_builder
like
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function not_like($field, $match = '', $side = 'both', $escape = NULL) { return $this->_like($field, $match, 'AND ', $side, 'NOT', $escape); }
NOT LIKE Generates a NOT LIKE portion of the query. Separates multiple calls with 'AND'. @param mixed $field @param string $match @param string $side @param bool $escape @return CI_DB_query_builder
not_like
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_like($field, $match = '', $side = 'both', $escape = NULL) { return $this->_like($field, $match, 'OR ', $side, '', $escape); }
OR LIKE Generates a %LIKE% portion of the query. Separates multiple calls with 'OR'. @param mixed $field @param string $match @param string $side @param bool $escape @return CI_DB_query_builder
or_like
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_not_like($field, $match = '', $side = 'both', $escape = NULL) { return $this->_like($field, $match, 'OR ', $side, 'NOT', $escape); }
OR NOT LIKE Generates a NOT LIKE portion of the query. Separates multiple calls with 'OR'. @param mixed $field @param string $match @param string $side @param bool $escape @return CI_DB_query_builder
or_not_like
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_group_start() { return $this->group_start('', 'OR '); }
Starts a query group, but ORs the group @return CI_DB_query_builder
or_group_start
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function not_group_start() { return $this->group_start('NOT ', 'AND '); }
Starts a query group, but NOTs the group @return CI_DB_query_builder
not_group_start
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_not_group_start() { return $this->group_start('NOT ', 'OR '); }
Starts a query group, but OR NOTs the group @return CI_DB_query_builder
or_not_group_start
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function having($key, $value = NULL, $escape = NULL) { return $this->_wh('qb_having', $key, $value, 'AND ', $escape); }
HAVING Separates multiple calls with 'AND'. @param string $key @param string $value @param bool $escape @return CI_DB_query_builder
having
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function or_having($key, $value = NULL, $escape = NULL) { return $this->_wh('qb_having', $key, $value, 'OR ', $escape); }
OR HAVING Separates multiple calls with 'OR'. @param string $key @param string $value @param bool $escape @return CI_DB_query_builder
or_having
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function get_compiled_select($table = '', $reset = TRUE) { if ($table !== '') { $this->_track_aliases($table); $this->from($table); } $select = $this->_compile_select(); if ($reset === TRUE) { $this->_reset_select(); } return $select; }
Get SELECT query string Compiles a SELECT query string and returns the sql. @param string the table name to select from (optional) @param bool TRUE: resets QB values; FALSE: leave QB values alone @return string
get_compiled_select
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function get($table = '', $limit = NULL, $offset = NULL) { if ($table !== '') { $this->_track_aliases($table); $this->from($table); } if ( ! empty($limit)) { $this->limit($limit, $offset); } $result = $this->query($this->_compile_select()); $this->_reset_select(); return $result; }
Get Compiles the select statement based on the other functions called and runs the query @param string the table @param string the limit clause @param string the offset clause @return CI_DB_result
get
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function count_all_results($table = '', $reset = TRUE) { if ($table !== '') { $this->_track_aliases($table); $this->from($table); } // ORDER BY usage is often problematic here (most notably // on Microsoft SQL Server) and ultimately unnecessary // for selecting COUNT(*) ... $qb_orderby = $this->qb_orderby; $qb_cache_orderby = $this->qb_cache_orderby; $this->qb_orderby = $this->qb_cache_orderby = NULL; $result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset) ? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results") : $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows'))); if ($reset === TRUE) { $this->_reset_select(); } else { $this->qb_orderby = $qb_orderby; $this->qb_cache_orderby = $qb_cache_orderby; } if ($result->num_rows() === 0) { return 0; } $row = $result->row(); return (int) $row->numrows; }
"Count All Results" query Generates a platform-specific query string that counts all records returned by an Query Builder query. @param string @param bool the reset clause @return int
count_all_results
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL) { if ($table !== '') { $this->from($table); } if ($where !== NULL) { $this->where($where); } if ( ! empty($limit)) { $this->limit($limit, $offset); } $result = $this->query($this->_compile_select()); $this->_reset_select(); return $result; }
Get_Where Allows the where clause, limit and offset to be added directly @param string $table @param string $where @param int $limit @param int $offset @return CI_DB_result
get_where
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function insert_batch($table, $set = NULL, $escape = NULL, $batch_size = 100) { if ($set === NULL) { if (empty($this->qb_set)) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } } else { if (empty($set)) { return ($this->db_debug) ? $this->display_error('insert_batch() called with no data') : FALSE; } $this->set_insert_batch($set, '', $escape); } if (strlen($table) === 0) { if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->qb_from[0]; } // Batch this baby $affected_rows = 0; for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size) { if ($this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, $batch_size)))) { $affected_rows += $this->affected_rows(); } } $this->_reset_write(); return $affected_rows; }
Insert_Batch Compiles batch insert strings and runs the queries @param string $table Table to insert into @param array $set An associative array of insert values @param bool $escape Whether to escape values and identifiers @return int Number of rows inserted or FALSE on failure
insert_batch
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _insert_batch($table, $keys, $values) { return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); }
Insert batch statement Generates a platform-specific insert string from the supplied data. @param string $table Table name @param array $keys INSERT keys @param array $values INSERT values @return string
_insert_batch
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function get_compiled_insert($table = '', $reset = TRUE) { if ($this->_validate_insert($table) === FALSE) { return FALSE; } $sql = $this->_insert( $this->protect_identifiers( $this->qb_from[0], TRUE, NULL, FALSE ), array_keys($this->qb_set), array_values($this->qb_set) ); if ($reset === TRUE) { $this->_reset_write(); } return $sql; }
Get INSERT query string Compiles an insert query and returns the sql @param string the table to insert into @param bool TRUE: reset QB values; FALSE: leave QB values alone @return string
get_compiled_insert
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function insert($table = '', $set = NULL, $escape = NULL) { if ($set !== NULL) { $this->set($set, '', $escape); } if ($this->_validate_insert($table) === FALSE) { return FALSE; } $sql = $this->_insert( $this->protect_identifiers( $this->qb_from[0], TRUE, $escape, FALSE ), array_keys($this->qb_set), array_values($this->qb_set) ); $this->_reset_write(); return $this->query($sql); }
Insert Compiles an insert string and runs the query @param string the table to insert data into @param array an associative array of insert values @param bool $escape Whether to escape values and identifiers @return bool TRUE on success, FALSE on failure
insert
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function replace($table = '', $set = NULL) { if ($set !== NULL) { $this->set($set); } if (count($this->qb_set) === 0) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table === '') { if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->qb_from[0]; } $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set)); $this->_reset_write(); return $this->query($sql); }
Replace Compiles an replace into string and runs the query @param string the table to replace data into @param array an associative array of insert values @return bool TRUE on success, FALSE on failure
replace
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _replace($table, $keys, $values) { return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; }
Replace statement Generates a platform-specific replace string from the supplied data @param string the table name @param array the insert keys @param array the insert values @return string
_replace
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _from_tables() { return implode(', ', $this->qb_from); }
FROM tables Groups tables in FROM clauses if needed, so there is no confusion about operator precedence. Note: This is only used (and overridden) by MySQL and CUBRID. @return string
_from_tables
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function get_compiled_update($table = '', $reset = TRUE) { // Combine any cached components with the current statements $this->_merge_cache(); if ($this->_validate_update($table) === FALSE) { return FALSE; } $sql = $this->_update($this->qb_from[0], $this->qb_set); if ($reset === TRUE) { $this->_reset_write(); } return $sql; }
Get UPDATE query string Compiles an update query and returns the sql @param string the table to update @param bool TRUE: reset QB values; FALSE: leave QB values alone @return string
get_compiled_update
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); if ($set !== NULL) { $this->set($set); } if ($this->_validate_update($table) === FALSE) { return FALSE; } if ($where !== NULL) { $this->where($where); } if ( ! empty($limit)) { $this->limit($limit); } $sql = $this->_update($this->qb_from[0], $this->qb_set); $this->_reset_write(); return $this->query($sql); }
UPDATE Compiles an update string and runs the query. @param string $table @param array $set An associative array of update values @param mixed $where @param int $limit @return bool TRUE on success, FALSE on failure
update
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function update_batch($table, $set = NULL, $index = NULL, $batch_size = 100) { // Combine any cached components with the current statements $this->_merge_cache(); if ($index === NULL) { return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE; } if ($set === NULL) { if (empty($this->qb_set_ub)) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } } else { if (empty($set)) { return ($this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE; } $this->set_update_batch($set, $index); } if (strlen($table) === 0) { if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->qb_from[0]; } // Batch this baby $affected_rows = 0; for ($i = 0, $total = count($this->qb_set_ub); $i < $total; $i += $batch_size) { if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index))) { $affected_rows += $this->affected_rows(); } $this->qb_where = array(); } $this->_reset_write(); return $affected_rows; }
Update_Batch Compiles an update string and runs the query @param string the table to retrieve the results from @param array an associative array of update values @param string the where key @return int number of rows affected or FALSE on failure
update_batch
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function empty_table($table = '') { if ($table === '') { if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->qb_from[0]; } else { $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); } $sql = $this->_delete($table); $this->_reset_write(); return $this->query($sql); }
Empty Table Compiles a delete string and runs "DELETE FROM table" @param string the table to empty @return bool TRUE on success, FALSE on failure
empty_table
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function truncate($table = '') { if ($table === '') { if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->qb_from[0]; } else { $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); } $sql = $this->_truncate($table); $this->_reset_write(); return $this->query($sql); }
Truncate Compiles a truncate string and runs the query If the database does not support the truncate() command This function maps to "DELETE FROM table" @param string the table to truncate @return bool TRUE on success, FALSE on failure
truncate
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _truncate($table) { return 'TRUNCATE '.$table; }
Truncate statement Generates a platform-specific truncate string from the supplied data If the database does not support the truncate() command, then this method maps to 'DELETE FROM table' @param string the table name @return string
_truncate
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function get_compiled_delete($table = '', $reset = TRUE) { $this->return_delete_sql = TRUE; $sql = $this->delete($table, '', NULL, $reset); $this->return_delete_sql = FALSE; return $sql; }
Get DELETE query string Compiles a delete query string and returns the sql @param string the table to delete from @param bool TRUE: reset QB values; FALSE: leave QB values alone @return string
get_compiled_delete
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function dbprefix($table = '') { if ($table === '') { $this->display_error('db_table_name_required'); } return $this->dbprefix.$table; }
DB Prefix Prepends a database prefix if one exists in configuration @param string the table @return string
dbprefix
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function set_dbprefix($prefix = '') { return $this->dbprefix = $prefix; }
Set DB Prefix Set's the DB Prefix to something new without needing to reconnect @param string the prefix @return string
set_dbprefix
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _compile_wh($qb_key) { if (count($this->$qb_key) > 0) { for ($i = 0, $c = count($this->$qb_key); $i < $c; $i++) { // Is this condition already compiled? if (is_string($this->{$qb_key}[$i])) { continue; } elseif ($this->{$qb_key}[$i]['escape'] === FALSE) { $this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition']; continue; } // Split multiple conditions $conditions = preg_split( '/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i', $this->{$qb_key}[$i]['condition'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); for ($ci = 0, $cc = count($conditions); $ci < $cc; $ci++) { if (($op = $this->_get_operator($conditions[$ci])) === FALSE OR ! preg_match('/^(\(?)(.*)('.preg_quote($op, '/').')\s*(.*(?<!\)))?(\)?)$/i', $conditions[$ci], $matches)) { continue; } // $matches = array( // 0 => '(test <= foo)', /* the whole thing */ // 1 => '(', /* optional */ // 2 => 'test', /* the field name */ // 3 => ' <= ', /* $op */ // 4 => 'foo', /* optional, if $op is e.g. 'IS NULL' */ // 5 => ')' /* optional */ // ); if ( ! empty($matches[4])) { $this->_is_literal($matches[4]) OR $matches[4] = $this->protect_identifiers(trim($matches[4])); $matches[4] = ' '.$matches[4]; } $conditions[$ci] = $matches[1].$this->protect_identifiers(trim($matches[2])) .' '.trim($matches[3]).$matches[4].$matches[5]; } $this->{$qb_key}[$i] = implode('', $conditions); } return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ") .implode("\n", $this->$qb_key); } return ''; }
Compile WHERE, HAVING statements Escapes identifiers in WHERE and HAVING statements at execution time. Required so that aliases are tracked properly, regardless of whether where(), or_where(), having(), or_having are called prior to from(), join() and dbprefix is added only if needed. @param string $qb_key 'qb_where' or 'qb_having' @return string SQL statement
_compile_wh
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _compile_group_by() { if (count($this->qb_groupby) > 0) { for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) { // Is it already compiled? if (is_string($this->qb_groupby[$i])) { continue; } $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE OR $this->_is_literal($this->qb_groupby[$i]['field'])) ? $this->qb_groupby[$i]['field'] : $this->protect_identifiers($this->qb_groupby[$i]['field']); } return "\nGROUP BY ".implode(', ', $this->qb_groupby); } return ''; }
Compile GROUP BY Escapes identifiers in GROUP BY statements at execution time. Required so that aliases are tracked properly, regardless of whether group_by() is called prior to from(), join() and dbprefix is added only if needed. @return string SQL statement
_compile_group_by
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _compile_order_by() { if (empty($this->qb_orderby)) { return ''; } for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) { if (is_string($this->qb_orderby[$i])) { continue; } if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field'])) { $this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']); } $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; } return "\nORDER BY ".implode(', ', $this->qb_orderby); }
Compile ORDER BY Escapes identifiers in ORDER BY statements at execution time. Required so that aliases are tracked properly, regardless of whether order_by() is called prior to from(), join() and dbprefix is added only if needed. @return string SQL statement
_compile_order_by
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _object_to_array($object) { if ( ! is_object($object)) { return $object; } $array = array(); foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion if ( ! is_object($val) && ! is_array($val) && $key !== '_parent_name') { $array[$key] = $val; } } return $array; }
Object to Array Takes an object as input and converts the class variables to array key/vals @param object @return array
_object_to_array
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _object_to_array_batch($object) { if ( ! is_object($object)) { return $object; } $array = array(); $out = get_object_vars($object); $fields = array_keys($out); foreach ($fields as $val) { // There are some built in keys we need to ignore for this conversion if ($val !== '_parent_name') { $i = 0; foreach ($out[$val] as $data) { $array[$i++][$val] = $data; } } } return $array; }
Object to Array Takes an object as input and converts the class variables to array key/vals @param object @return array
_object_to_array_batch
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function flush_cache() { $this->_reset_run(array( 'qb_cache_select' => array(), 'qb_cache_from' => array(), 'qb_cache_join' => array(), 'qb_cache_where' => array(), 'qb_cache_groupby' => array(), 'qb_cache_having' => array(), 'qb_cache_orderby' => array(), 'qb_cache_set' => array(), 'qb_cache_exists' => array(), 'qb_cache_no_escape' => array(), 'qb_cache_aliased_tables' => array() )); return $this; }
Flush Cache Empties the QB cache @return CI_DB_query_builder
flush_cache
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _merge_cache() { if (count($this->qb_cache_exists) === 0) { return; } elseif (in_array('select', $this->qb_cache_exists, TRUE)) { $qb_no_escape = $this->qb_cache_no_escape; } foreach (array_unique($this->qb_cache_exists) as $val) // select, from, etc. { $qb_variable = 'qb_'.$val; $qb_cache_var = 'qb_cache_'.$val; $qb_new = $this->$qb_cache_var; for ($i = 0, $c = count($this->$qb_variable); $i < $c; $i++) { if ( ! in_array($this->{$qb_variable}[$i], $qb_new, TRUE)) { $qb_new[] = $this->{$qb_variable}[$i]; if ($val === 'select') { $qb_no_escape[] = $this->qb_no_escape[$i]; } } } $this->$qb_variable = $qb_new; if ($val === 'select') { $this->qb_no_escape = $qb_no_escape; } } }
Merge Cache When called, this function merges any cached QB arrays with locally called ones. @return void
_merge_cache
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _is_literal($str) { $str = trim($str); if (empty($str) OR ctype_digit($str) OR (string) (float) $str === $str OR in_array(strtoupper($str), array('TRUE', 'FALSE'), TRUE)) { return TRUE; } static $_str; if (empty($_str)) { $_str = ($this->_escape_char !== '"') ? array('"', "'") : array("'"); } return in_array($str[0], $_str, TRUE); }
Is literal Determines if a string represents a literal value or a field name @param string $str @return bool
_is_literal
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
public function reset_query() { $this->_reset_select(); $this->_reset_write(); return $this; }
Reset Query Builder values. Publicly-visible method to reset the QB values. @return CI_DB_query_builder
reset_query
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _reset_run($qb_reset_items) { foreach ($qb_reset_items as $item => $default_value) { $this->$item = $default_value; } }
Resets the query builder values. Called by the get() function @param array An array of fields to reset @return void
_reset_run
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _reset_select() { $this->_reset_run(array( 'qb_select' => array(), 'qb_from' => array(), 'qb_join' => array(), 'qb_where' => array(), 'qb_groupby' => array(), 'qb_having' => array(), 'qb_orderby' => array(), 'qb_aliased_tables' => array(), 'qb_no_escape' => array(), 'qb_distinct' => FALSE, 'qb_limit' => FALSE, 'qb_offset' => FALSE )); }
Resets the query builder values. Called by the get() function @return void
_reset_select
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _reset_write() { $this->_reset_run(array( 'qb_set' => array(), 'qb_set_ub' => array(), 'qb_from' => array(), 'qb_join' => array(), 'qb_where' => array(), 'qb_orderby' => array(), 'qb_keys' => array(), 'qb_limit' => FALSE )); }
Resets the query builder "write" values. Called by the insert() update() insert_batch() update_batch() and delete() functions @return void
_reset_write
php
ronknight/InventorySystem
system/database/DB_query_builder.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_query_builder.php
MIT
protected function _drop_table($table, $if_exists) { $sql = 'DROP TABLE'; if ($if_exists) { if ($this->_drop_table_if === FALSE) { if ( ! $this->db->table_exists($table)) { return TRUE; } } else { $sql = sprintf($this->_drop_table_if, $this->db->escape_identifiers($table)); } } return $sql.' '.$this->db->escape_identifiers($table); }
Drop Table Generates a platform-specific DROP TABLE string @param string $table Table name @param bool $if_exists Whether to add an IF EXISTS condition @return mixed (Returns a platform-specific DROP table string, or TRUE to indicate there's nothing to do)
_drop_table
php
ronknight/InventorySystem
system/database/DB_forge.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_forge.php
MIT
protected function _attr_type(&$attributes) { // Usually overridden by drivers }
Field attribute TYPE Performs a data type mapping between different databases. @param array &$attributes @return void
_attr_type
php
ronknight/InventorySystem
system/database/DB_forge.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_forge.php
MIT
protected function _attr_auto_increment(&$attributes, &$field) { if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) { $field['auto_increment'] = ' AUTO_INCREMENT'; } }
Field attribute AUTO_INCREMENT @param array &$attributes @param array &$field @return void
_attr_auto_increment
php
ronknight/InventorySystem
system/database/DB_forge.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_forge.php
MIT
protected function _reset() { $this->fields = $this->keys = $this->primary_keys = array(); }
Reset Resets table creation vars @return void
_reset
php
ronknight/InventorySystem
system/database/DB_forge.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/DB_forge.php
MIT
public function num_fields() { return odbc_num_fields($this->result_id); }
Number of fields in the result set @return int
num_fields
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_result.php
MIT
public function list_fields() { $field_names = array(); $num_fields = $this->num_fields(); if ($num_fields > 0) { for ($i = 1; $i <= $num_fields; $i++) { $field_names[] = odbc_field_name($this->result_id, $i); } } return $field_names; }
Fetch Field Names Generates an array of column names @return array
list_fields
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_result.php
MIT
public function field_data() { $retval = array(); for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++) { $retval[$i] = new stdClass(); $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index); $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index); $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index); $retval[$i]->primary_key = 0; $retval[$i]->default = ''; } return $retval; }
Field data Generates an array of objects containing field meta-data @return array
field_data
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_result.php
MIT
protected function _fetch_assoc() { return odbc_fetch_array($this->result_id); }
Result - associative array Returns the result set as an array @return array
_fetch_assoc
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_result.php
MIT
protected function _fetch_object($class_name = 'stdClass') { $row = odbc_fetch_object($this->result_id); if ($class_name === 'stdClass' OR ! $row) { return $row; } $class_name = new $class_name(); foreach ($row as $key => $value) { $class_name->$key = $value; } return $class_name; }
Result - object Returns the result set as an object @param string $class_name @return object
_fetch_object
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_result.php
MIT
public function db_connect($persistent = FALSE) { return ($persistent === TRUE) ? odbc_pconnect($this->dsn, $this->username, $this->password) : odbc_connect($this->dsn, $this->username, $this->password); }
Non-persistent database connection @param bool $persistent @return resource
db_connect
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_driver.php
MIT
public function is_write_type($sql) { if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) { return FALSE; } return parent::is_write_type($sql); }
Determines if a query is a "write" type. @param string An SQL query string @return bool
is_write_type
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_driver.php
MIT
protected function _escape_str($str) { $this->display_error('db_unsupported_feature'); }
Platform-dependent string escape @param string @return string
_escape_str
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_driver.php
MIT
protected function _list_tables($prefix_limit = FALSE) { $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'"; if ($prefix_limit !== FALSE && $this->dbprefix !== '') { return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' " .sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; }
Show table query Generates a platform-specific query string so that the table names can be fetched @param bool $prefix_limit @return string
_list_tables
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_driver.php
MIT
protected function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$table; }
Show column query Generates a platform-specific query string so that the column names can be fetched @param string $table @return string
_list_columns
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_driver.php
MIT
protected function _field_data($table) { return 'SELECT TOP 1 FROM '.$table; }
Field data query Generates a platform-specific query so that the column data can be retrieved @param string $table @return string
_field_data
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_driver.php
MIT
protected function _attr_auto_increment(&$attributes, &$field) { // Not supported (in most databases at least) }
Field attribute AUTO_INCREMENT @param array &$attributes @param array &$field @return void
_attr_auto_increment
php
ronknight/InventorySystem
system/database/drivers/odbc/odbc_forge.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/odbc/odbc_forge.php
MIT
public function num_rows() { return $this->num_rows; }
Number of rows in the result set @return int
num_rows
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
public function num_fields() { return mysql_num_fields($this->result_id); }
Number of fields in the result set @return int
num_fields
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
public function list_fields() { $field_names = array(); mysql_field_seek($this->result_id, 0); while ($field = mysql_fetch_field($this->result_id)) { $field_names[] = $field->name; } return $field_names; }
Fetch Field Names Generates an array of column names @return array
list_fields
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
public function field_data() { $retval = array(); for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { $retval[$i] = new stdClass(); $retval[$i]->name = mysql_field_name($this->result_id, $i); $retval[$i]->type = mysql_field_type($this->result_id, $i); $retval[$i]->max_length = mysql_field_len($this->result_id, $i); $retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE); } return $retval; }
Field data Generates an array of objects containing field meta-data @return array
field_data
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
public function data_seek($n = 0) { return $this->num_rows ? mysql_data_seek($this->result_id, $n) : FALSE; }
Data Seek Moves the internal pointer to the desired offset. We call this internally before fetching results to make sure the result set starts at zero. @param int $n @return bool
data_seek
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
protected function _fetch_assoc() { return mysql_fetch_assoc($this->result_id); }
Result - associative array Returns the result set as an array @return array
_fetch_assoc
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
protected function _fetch_object($class_name = 'stdClass') { return mysql_fetch_object($this->result_id, $class_name); }
Result - object Returns the result set as an object @param string $class_name @return object
_fetch_object
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_result.php
MIT
public function db_connect($persistent = FALSE) { $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS; if ($this->encrypt === TRUE) { $client_flags = $client_flags | MYSQL_CLIENT_SSL; } // Error suppression is necessary mostly due to PHP 5.5+ issuing E_DEPRECATED messages $this->conn_id = ($persistent === TRUE) ? mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags) : mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags); // ---------------------------------------------------------------- // Select the DB... assuming a database name is specified in the config file if ($this->database !== '' && ! $this->db_select()) { log_message('error', 'Unable to select database: '.$this->database); return ($this->db_debug === TRUE) ? $this->display_error('db_unable_to_select', $this->database) : FALSE; } if (isset($this->stricton) && is_resource($this->conn_id)) { if ($this->stricton) { $this->simple_query('SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); } else { $this->simple_query( 'SET SESSION sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@sql_mode, "STRICT_ALL_TABLES,", ""), ",STRICT_ALL_TABLES", ""), "STRICT_ALL_TABLES", ""), "STRICT_TRANS_TABLES,", ""), ",STRICT_TRANS_TABLES", ""), "STRICT_TRANS_TABLES", "")' ); } } return $this->conn_id; }
Non-persistent database connection @param bool $persistent @return resource
db_connect
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
public function reconnect() { if (mysql_ping($this->conn_id) === FALSE) { $this->conn_id = FALSE; } }
Reconnect Keep / reestablish the db connection if no queries have been sent for a length of time exceeding the server's idle timeout @return void
reconnect
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
protected function _prep_query($sql) { // mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack // modifies the query so that it a proper number of affected rows is returned. if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { return trim($sql).' WHERE 1=1'; } return $sql; }
Prep the query If needed, each database adapter can prep the query string @param string $sql an SQL query @return string
_prep_query
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
protected function _escape_str($str) { return mysql_real_escape_string($str, $this->conn_id); }
Platform-dependent string escape @param string @return string
_escape_str
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
protected function _list_tables($prefix_limit = FALSE) { $sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database); if ($prefix_limit !== FALSE && $this->dbprefix !== '') { return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; }
List table query Generates a platform-specific query string so that the table names can be fetched @param bool $prefix_limit @return string
_list_tables
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
protected function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); }
Show column query Generates a platform-specific query string so that the column names can be fetched @param string $table @return string
_list_columns
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
public function field_data($table) { if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) { return FALSE; } $query = $query->result_object(); $retval = array(); for ($i = 0, $c = count($query); $i < $c; $i++) { $retval[$i] = new stdClass(); $retval[$i]->name = $query[$i]->Field; sscanf($query[$i]->Type, '%[a-z](%d)', $retval[$i]->type, $retval[$i]->max_length ); $retval[$i]->default = $query[$i]->Default; $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); } return $retval; }
Returns an object with field data @param string $table @return array
field_data
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
protected function _from_tables() { if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } return implode(', ', $this->qb_from); }
FROM tables Groups tables in FROM clauses if needed, so there is no confusion about operator precedence. @return string
_from_tables
php
ronknight/InventorySystem
system/database/drivers/mysql/mysql_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysql/mysql_driver.php
MIT
public function reconnect() { if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE) { $this->conn_id = FALSE; } }
Reconnect Keep / reestablish the db connection if no queries have been sent for a length of time exceeding the server's idle timeout @return void
reconnect
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
protected function _prep_query($sql) { // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack // modifies the query so that it a proper number of affected rows is returned. if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { return trim($sql).' WHERE 1=1'; } return $sql; }
Prep the query If needed, each database adapter can prep the query string @param string $sql an SQL query @return string
_prep_query
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
protected function _escape_str($str) { return $this->conn_id->real_escape_string($str); }
Platform-dependent string escape @param string @return string
_escape_str
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
protected function _list_tables($prefix_limit = FALSE) { $sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database); if ($prefix_limit !== FALSE && $this->dbprefix !== '') { return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; }
List table query Generates a platform-specific query string so that the table names can be fetched @param bool $prefix_limit @return string
_list_tables
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
protected function _list_columns($table = '') { return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); }
Show column query Generates a platform-specific query string so that the column names can be fetched @param string $table @return string
_list_columns
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
public function field_data($table) { if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) { return FALSE; } $query = $query->result_object(); $retval = array(); for ($i = 0, $c = count($query); $i < $c; $i++) { $retval[$i] = new stdClass(); $retval[$i]->name = $query[$i]->Field; sscanf($query[$i]->Type, '%[a-z](%d)', $retval[$i]->type, $retval[$i]->max_length ); $retval[$i]->default = $query[$i]->Default; $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); } return $retval; }
Returns an object with field data @param string $table @return array
field_data
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
protected function _from_tables() { if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } return implode(', ', $this->qb_from); }
FROM tables Groups tables in FROM clauses if needed, so there is no confusion about operator precedence. @return string
_from_tables
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_driver.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_driver.php
MIT
public function num_rows() { return is_int($this->num_rows) ? $this->num_rows : $this->num_rows = $this->result_id->num_rows; }
Number of rows in the result set @return int
num_rows
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_result.php
MIT
public function num_fields() { return $this->result_id->field_count; }
Number of fields in the result set @return int
num_fields
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_result.php
MIT
public function list_fields() { $field_names = array(); $this->result_id->field_seek(0); while ($field = $this->result_id->fetch_field()) { $field_names[] = $field->name; } return $field_names; }
Fetch Field Names Generates an array of column names @return array
list_fields
php
ronknight/InventorySystem
system/database/drivers/mysqli/mysqli_result.php
https://github.com/ronknight/InventorySystem/blob/master/system/database/drivers/mysqli/mysqli_result.php
MIT