diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-07-05 15:31:12 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-07-05 15:31:12 +0200 |
commit | 92d18a7b6c46eadc9db58ca60ffce3980e2313ff (patch) | |
tree | b0a869a5312279d65c3e920ffbf0b32344ab1d0f /system/database/DB_driver.php | |
parent | d66872ae5d7cd4d2b531251a9c63528e81af3322 (diff) | |
parent | 7ca36131d881d3f83a86d824263d4abd65439e12 (diff) |
Merge upstream branch
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r-- | system/database/DB_driver.php | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 877147c5f..eca2e68a7 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -45,7 +45,7 @@ abstract class CI_DB_driver { public $password; public $hostname; public $database; - public $dbdriver = 'mysql'; + public $dbdriver = 'mysqli'; public $subdriver; public $dbprefix = ''; public $char_set = 'utf8'; @@ -78,6 +78,19 @@ abstract class CI_DB_driver { protected $_protect_identifiers = TRUE; protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped + /** + * 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. + */ + protected $_count_string = 'SELECT COUNT(*) AS '; + + /** + * Constructor + * + * @param array + * @return void + */ public function __construct($params) { if (is_array($params)) @@ -856,7 +869,7 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- /** - * Fetch MySQL Field Names + * Fetch Field Names * * @param string the table name * @return array @@ -1031,6 +1044,23 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _insert($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** * Generate an update string * * @param string the table upon which the query will be performed @@ -1083,6 +1113,41 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @param array the like clause + * @return string + */ + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + { + foreach ($values as $key => $val) + { + $valstr[] = $key.' = '.$val; + } + + $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); + + if ( ! empty($like)) + { + $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); + } + + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .$where + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .($limit ? ' LIMIT '.$limit : ''); + } + + // -------------------------------------------------------------------- + + /** * Tests whether the string has an SQL operator * * @param string @@ -1172,7 +1237,6 @@ abstract class CI_DB_driver { return $this->cache_on = FALSE; } - // -------------------------------------------------------------------- /** |