summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
Diffstat (limited to 'system/database')
-rwxr-xr-xsystem/database/DB.php59
-rw-r--r--system/database/DB_active_rec.php600
-rw-r--r--system/database/DB_cache.php51
-rw-r--r--system/database/DB_driver.php79
-rw-r--r--system/database/DB_forge.php141
-rw-r--r--system/database/DB_result.php85
-rw-r--r--system/database/DB_utility.php161
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php2
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php2
-rw-r--r--system/database/drivers/cubrid/cubrid_result.php2
-rw-r--r--system/database/drivers/cubrid/cubrid_utility.php2
-rw-r--r--system/database/drivers/mssql/mssql_driver.php23
-rw-r--r--system/database/drivers/mssql/mssql_forge.php2
-rw-r--r--system/database/drivers/mssql/mssql_result.php2
-rw-r--r--system/database/drivers/mssql/mssql_utility.php2
-rw-r--r--system/database/drivers/mysql/mysql_driver.php338
-rw-r--r--system/database/drivers/mysql/mysql_forge.php133
-rw-r--r--system/database/drivers/mysql/mysql_result.php59
-rw-r--r--system/database/drivers/mysql/mysql_utility.php77
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php335
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php139
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php59
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php36
-rw-r--r--system/database/drivers/oci8/oci8_driver.php2
-rw-r--r--system/database/drivers/oci8/oci8_forge.php2
-rw-r--r--system/database/drivers/oci8/oci8_result.php2
-rw-r--r--system/database/drivers/oci8/oci8_utility.php2
-rw-r--r--system/database/drivers/odbc/odbc_driver.php2
-rw-r--r--system/database/drivers/odbc/odbc_forge.php2
-rw-r--r--system/database/drivers/odbc/odbc_result.php2
-rw-r--r--system/database/drivers/odbc/odbc_utility.php2
-rw-r--r--system/database/drivers/pdo/pdo_driver.php283
-rw-r--r--system/database/drivers/pdo/pdo_forge.php14
-rw-r--r--system/database/drivers/pdo/pdo_result.php69
-rw-r--r--system/database/drivers/pdo/pdo_utility.php2
-rw-r--r--system/database/drivers/postgre/postgre_driver.php2
-rw-r--r--system/database/drivers/postgre/postgre_forge.php109
-rw-r--r--system/database/drivers/postgre/postgre_result.php2
-rw-r--r--system/database/drivers/postgre/postgre_utility.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php23
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_result.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_utility.php2
47 files changed, 1325 insertions, 1600 deletions
diff --git a/system/database/DB.php b/system/database/DB.php
index 5c90f44f3..d06ffb40e 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Initialize the database
*
@@ -42,17 +40,15 @@ function &DB($params = '', $active_record_override = NULL)
if (is_string($params) AND strpos($params, '://') === FALSE)
{
// Is the config file in the environment folder?
- if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+ if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+ AND ! file_exists($file_path = APPPATH.'config/database.php'))
{
- if ( ! file_exists($file_path = APPPATH.'config/database.php'))
- {
- show_error('The configuration file database.php does not exist.');
- }
+ show_error('The configuration file database.php does not exist.');
}
include($file_path);
- if ( ! isset($db) OR count($db) == 0)
+ if ( ! isset($db) OR count($db) === 0)
{
show_error('No database connection settings were found in the database config file.');
}
@@ -78,33 +74,32 @@ function &DB($params = '', $active_record_override = NULL)
* parameter. DSNs must have this prototype:
* $dsn = 'driver://username:password@hostname/database';
*/
-
if (($dns = @parse_url($params)) === FALSE)
{
show_error('Invalid DB Connection String');
}
$params = array(
- 'dbdriver' => $dns['scheme'],
- 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
- 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
- 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
- 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
- );
+ 'dbdriver' => $dns['scheme'],
+ 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
+ 'port' => (isset($dns['port'])) ? rawurldecode($dns['port']) : '',
+ 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
+ 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
+ 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
+ );
// were additional config items set?
if (isset($dns['query']))
{
parse_str($dns['query'], $extra);
-
foreach ($extra as $key => $val)
{
// booleans please
- if (strtoupper($val) == "TRUE")
+ if (strtoupper($val) === 'TRUE')
{
$val = TRUE;
}
- elseif (strtoupper($val) == "FALSE")
+ elseif (strtoupper($val) === 'FALSE')
{
$val = FALSE;
}
@@ -114,17 +109,15 @@ function &DB($params = '', $active_record_override = NULL)
}
}
- // No DB specified yet? Beat them senseless...
+ // No DB specified yet? Beat them senseless...
if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
{
show_error('You have not selected a database type to connect to.');
}
- // Load the DB classes. Note: Since the active record class is optional
+ // Load the DB classes. Note: Since the active record class is optional
// we need to dynamically create a class that extends proper parent class
// based on whether we're using the active record class or not.
- // Kudos to Paul for discovering this clever use of eval()
-
if ($active_record_override !== NULL)
{
$active_record = $active_record_override;
@@ -135,18 +128,14 @@ function &DB($params = '', $active_record_override = NULL)
if ( ! isset($active_record) OR $active_record == TRUE)
{
require_once(BASEPATH.'database/DB_active_rec.php');
-
if ( ! class_exists('CI_DB'))
{
- eval('class CI_DB extends CI_DB_active_record { }');
+ class CI_DB extends CI_DB_active_record { }
}
}
- else
+ elseif ( ! class_exists('CI_DB'))
{
- if ( ! class_exists('CI_DB'))
- {
- eval('class CI_DB extends CI_DB_driver { }');
- }
+ class CI_DB extends CI_DB_driver { }
}
require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
@@ -168,7 +157,5 @@ function &DB($params = '', $active_record_override = NULL)
return $DB;
}
-
-
/* End of file DB.php */
-/* Location: ./system/database/DB.php */ \ No newline at end of file
+/* Location: ./system/database/DB.php */
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 530b44e09..eaae23f30 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -40,44 +40,44 @@
*/
class CI_DB_active_record extends CI_DB_driver {
- protected $return_delete_sql = FALSE;
- protected $reset_delete_data = FALSE;
-
+ protected $return_delete_sql = FALSE;
+ protected $reset_delete_data = FALSE;
+
protected $ar_select = array();
protected $ar_distinct = FALSE;
- protected $ar_from = array();
- protected $ar_join = array();
- protected $ar_where = array();
- protected $ar_like = array();
+ protected $ar_from = array();
+ protected $ar_join = array();
+ protected $ar_where = array();
+ protected $ar_like = array();
protected $ar_groupby = array();
protected $ar_having = array();
- protected $ar_keys = array();
- protected $ar_limit = FALSE;
+ protected $ar_keys = array();
+ protected $ar_limit = FALSE;
protected $ar_offset = FALSE;
- protected $ar_order = FALSE;
+ protected $ar_order = FALSE;
protected $ar_orderby = array();
- protected $ar_set = array();
+ protected $ar_set = array();
protected $ar_wherein = array();
- protected $ar_aliased_tables = array();
+ protected $ar_aliased_tables = array();
protected $ar_store_array = array();
+ protected $ar_where_group_started = FALSE;
+ protected $ar_where_group_count = 0;
// Active Record Caching variables
- protected $ar_caching = FALSE;
- protected $ar_cache_exists = array();
- protected $ar_cache_select = array();
- protected $ar_cache_from = array();
- protected $ar_cache_join = array();
- protected $ar_cache_where = array();
- protected $ar_cache_like = array();
- protected $ar_cache_groupby = array();
- protected $ar_cache_having = array();
- protected $ar_cache_orderby = array();
- protected $ar_cache_set = array();
-
- protected $ar_no_escape = array();
- protected $ar_cache_no_escape = array();
-
- // --------------------------------------------------------------------
+ protected $ar_caching = FALSE;
+ protected $ar_cache_exists = array();
+ protected $ar_cache_select = array();
+ protected $ar_cache_from = array();
+ protected $ar_cache_join = array();
+ protected $ar_cache_where = array();
+ protected $ar_cache_like = array();
+ protected $ar_cache_groupby = array();
+ protected $ar_cache_having = array();
+ protected $ar_cache_orderby = array();
+ protected $ar_cache_set = array();
+
+ protected $ar_no_escape = array();
+ protected $ar_cache_no_escape = array();
/**
* Select
@@ -111,6 +111,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
}
+
return $this;
}
@@ -186,7 +187,7 @@ class CI_DB_active_record extends CI_DB_driver {
* select_max()
* select_min()
* select_avg()
- * select_sum()
+ * select_sum()
*
* @param string the field
* @param string an alias
@@ -212,7 +213,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
-
$this->ar_select[] = $sql;
if ($this->ar_caching === TRUE)
@@ -236,7 +236,8 @@ class CI_DB_active_record extends CI_DB_driver {
{
if (strpos($item, '.') !== FALSE)
{
- return end(explode('.', $item));
+ $item = explode('.', $item);
+ return end($item);
}
return $item;
@@ -278,30 +279,27 @@ class CI_DB_active_record extends CI_DB_driver {
{
$v = trim($v);
$this->_track_aliases($v);
-
- $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $v = $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $this->ar_cache_from[] = $v;
$this->ar_cache_exists[] = 'from';
}
}
-
}
else
{
$val = trim($val);
- // Extract any aliases that might exist. We use this information
+ // 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($val);
-
- $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->ar_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->ar_cache_from[] = $val;
$this->ar_cache_exists[] = 'from';
}
}
@@ -338,23 +336,19 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- // Extract any aliases that might exist. We use this information
+ // 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);
// Strip apart the condition and protect the identifiers
if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
{
- $match[1] = $this->_protect_identifiers($match[1]);
- $match[3] = $this->_protect_identifiers($match[3]);
-
- $cond = $match[1].$match[2].$match[3];
+ $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
}
// Assemble the JOIN statement
- $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+ $this->ar_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
- $this->ar_join[] = $join;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_join[] = $join;
@@ -412,6 +406,8 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{
+ $type = $this->_group_get_type($type);
+
if ( ! is_array($key))
{
$key = array($key => $value);
@@ -425,7 +421,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
+ $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
if (is_null($v) && ! $this->_has_operator($k))
{
@@ -438,10 +434,9 @@ class CI_DB_active_record extends CI_DB_driver {
if ($escape === TRUE)
{
$k = $this->_protect_identifiers($k, FALSE, $escape);
-
$v = ' '.$this->escape($v);
}
-
+
if ( ! $this->_has_operator($k))
{
$k .= ' = ';
@@ -453,7 +448,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$this->ar_where[] = $prefix.$k.$v;
-
if ($this->ar_caching === TRUE)
{
$this->ar_cache_where[] = $prefix.$k.$v;
@@ -553,6 +547,8 @@ class CI_DB_active_record extends CI_DB_driver {
return;
}
+ $type = $this->_group_get_type($type);
+
if ( ! is_array($values))
{
$values = array($values);
@@ -565,11 +561,9 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_wherein[] = $this->escape($value);
}
- $prefix = (count($this->ar_where) == 0) ? '' : $type;
-
- $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
+ $prefix = (count($this->ar_where) === 0) ? '' : $type;
+ $this->ar_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
- $this->ar_where[] = $where_in;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_where[] = $where_in;
@@ -663,6 +657,8 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{
+ $type = $this->_group_get_type($type);
+
if ( ! is_array($field))
{
$field = array($field => $match);
@@ -671,20 +667,18 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($field as $k => $v)
{
$k = $this->_protect_identifiers($k);
-
- $prefix = (count($this->ar_like) == 0) ? '' : $type;
-
+ $prefix = (count($this->ar_like) === 0) ? '' : $type;
$v = $this->escape_like_str($v);
- if ($side == 'none')
+ if ($side === 'none')
{
$like_statement = $prefix." $k $not LIKE '{$v}'";
}
- elseif ($side == 'before')
+ elseif ($side === 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
- elseif ($side == 'after')
+ elseif ($side === 'after')
{
$like_statement = $prefix." $k $not LIKE '{$v}%'";
}
@@ -707,12 +701,114 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
+
return $this;
}
// --------------------------------------------------------------------
/**
+ * Starts a query group.
+ *
+ * @param string (Internal use only)
+ * @param string (Internal use only)
+ * @return object
+ */
+ public function group_start($not = '', $type = 'AND ')
+ {
+ $type = $this->_group_get_type($type);
+ $this->ar_where_group_started = TRUE;
+ $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
+ $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' (';
+
+ if ($this->ar_caching)
+ {
+ $this->ar_cache_where[] = $value;
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group, but ORs the group
+ *
+ * @return object
+ */
+ public function or_group_start()
+ {
+ return $this->group_start('', 'OR ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group, but NOTs the group
+ *
+ * @return object
+ */
+ public function not_group_start()
+ {
+ return $this->group_start('NOT ', 'AND ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group, but OR NOTs the group
+ *
+ * @return object
+ */
+ public function or_not_group_start()
+ {
+ return $this->group_start('NOT ', 'OR ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Ends a query group
+ *
+ * @return object
+ */
+ public function group_end()
+ {
+ $this->ar_where_group_started = FALSE;
+ $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
+
+ if ($this->ar_caching)
+ {
+ $this->ar_cache_where[] = $value;
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Group_get_type
+ *
+ * Called by group_start(), _like(), _where() and _where_in()
+ *
+ * @param string
+ * @return string
+ */
+ protected function _group_get_type($type)
+ {
+ if ($this->ar_where_group_started)
+ {
+ $type = '';
+ $this->ar_where_group_started = FALSE;
+ }
+
+ return $type;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* GROUP BY
*
* @param string
@@ -731,15 +827,16 @@ class CI_DB_active_record extends CI_DB_driver {
if ($val != '')
{
- $this->ar_groupby[] = $this->_protect_identifiers($val);
+ $this->ar_groupby[] = $val = $this->_protect_identifiers($val);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
+ $this->ar_cache_groupby[] = $val;
$this->ar_cache_exists[] = 'groupby';
}
}
}
+
return $this;
}
@@ -795,7 +892,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_having) == 0) ? '' : $type;
+ $prefix = (count($this->ar_having) === 0) ? '' : $type;
if ($escape === TRUE)
{
@@ -835,7 +932,7 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function order_by($orderby, $direction = '', $escape = TRUE)
{
- if (strtolower($direction) == 'random')
+ if (strtolower($direction) === 'random')
{
$orderby = ''; // Random results want or don't need a field name
$direction = $this->_random_keyword;
@@ -846,7 +943,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
- if ((strpos($orderby, ',') !== FALSE) && ($escape === TRUE))
+ if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
{
$temp = array();
foreach (explode(',', $orderby) as $part)
@@ -862,7 +959,7 @@ class CI_DB_active_record extends CI_DB_driver {
$orderby = implode(', ', $temp);
}
- else if ($direction != $this->_random_keyword)
+ elseif ($direction != $this->_random_keyword)
{
if ($escape === TRUE)
{
@@ -870,9 +967,8 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- $orderby_statement = $orderby.$direction;
+ $this->ar_orderby[] = $orderby_statement = $orderby.$direction;
- $this->ar_orderby[] = $orderby_statement;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_orderby[] = $orderby_statement;
@@ -950,7 +1046,7 @@ class CI_DB_active_record extends CI_DB_driver {
return $this;
}
-
+
// --------------------------------------------------------------------
/**
@@ -963,24 +1059,24 @@ class CI_DB_active_record extends CI_DB_driver {
* @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
* @return string
*/
- public function get_compiled_select($table = '', $reset = TRUE)
+ 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;
}
-
+
// --------------------------------------------------------------------
/**
@@ -1007,9 +1103,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit, $offset);
}
- $sql = $this->_compile_select();
-
- $result = $this->query($sql);
+ $result = $this->query($this->_compile_select());
$this->_reset_select();
return $result;
}
@@ -1031,20 +1125,17 @@ class CI_DB_active_record extends CI_DB_driver {
$this->from($table);
}
- $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
-
- $query = $this->query($sql);
+ $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
$this->_reset_select();
- if ($query->num_rows() == 0)
+ if ($result->num_rows() === 0)
{
return 0;
}
- $row = $query->row();
+ $row = $result->row();
return (int) $row->numrows;
}
-
// --------------------------------------------------------------------
/**
@@ -1074,9 +1165,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit, $offset);
}
- $sql = $this->_compile_select();
-
- $result = $this->query($sql);
+ $result = $this->query($this->_compile_select());
$this->_reset_select();
return $result;
}
@@ -1099,11 +1188,11 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set_insert_batch($set);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
if ($this->db_debug)
{
- //No valid data array. Folds in cases where keys and values did not match up
+ // No valid data array. Folds in cases where keys and values did not match up
return $this->display_error('db_must_use_set');
}
return FALSE;
@@ -1113,30 +1202,19 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+ for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
-
- $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
-
- //echo $sql;
-
- $this->query($sql);
+ $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
}
$this->_reset_write();
-
-
return TRUE;
}
@@ -1180,7 +1258,6 @@ class CI_DB_active_record extends CI_DB_driver {
else
{
$clean = array();
-
foreach ($row as $value)
{
$clean[] = $this->escape($value);
@@ -1197,7 +1274,7 @@ class CI_DB_active_record extends CI_DB_driver {
return $this;
}
-
+
// --------------------------------------------------------------------
/**
@@ -1211,25 +1288,25 @@ class CI_DB_active_record extends CI_DB_driver {
* @return string
*/
public function get_compiled_insert($table = '', $reset = TRUE)
- {
+ {
if ($this->_validate_insert($table) === FALSE)
{
return FALSE;
}
-
+
$sql = $this->_insert(
$this->_protect_identifiers(
$this->ar_from[0], TRUE, NULL, FALSE
),
- array_keys($this->ar_set),
+ array_keys($this->ar_set),
array_values($this->ar_set)
);
-
+
if ($reset === TRUE)
{
$this->_reset_write();
}
-
+
return $sql;
}
@@ -1251,24 +1328,24 @@ class CI_DB_active_record extends CI_DB_driver {
{
$this->set($set);
}
-
+
if ($this->_validate_insert($table) === FALSE)
{
return FALSE;
}
-
+
$sql = $this->_insert(
$this->_protect_identifiers(
$this->ar_from[0], TRUE, NULL, FALSE
- ),
- array_keys($this->ar_set),
+ ),
+ array_keys($this->ar_set),
array_values($this->ar_set)
);
$this->_reset_write();
return $this->query($sql);
}
-
+
// --------------------------------------------------------------------
/**
@@ -1282,33 +1359,25 @@ class CI_DB_active_record extends CI_DB_driver {
* @param string the table to insert data into
* @return string
*/
- protected function _validate_insert($table = '')
+ protected function _validate_insert($table = '')
{
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
{
$this->ar_from[0] = $table;
}
-
+
return TRUE;
}
@@ -1330,35 +1399,26 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set($set);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
$sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
-
$this->_reset_write();
return $this->query($sql);
}
-
+
// --------------------------------------------------------------------
/**
@@ -1375,22 +1435,22 @@ class CI_DB_active_record extends CI_DB_driver {
{
// Combine any cached components with the current statements
$this->_merge_cache();
-
+
if ($this->_validate_update($table) === FALSE)
{
return FALSE;
}
-
+
$sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
-
+
if ($reset === TRUE)
{
$this->_reset_write();
}
-
+
return $sql;
}
-
+
// --------------------------------------------------------------------
/**
@@ -1429,11 +1489,10 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
-
$this->_reset_write();
return $this->query($sql);
}
-
+
// --------------------------------------------------------------------
/**
@@ -1445,36 +1504,30 @@ class CI_DB_active_record extends CI_DB_driver {
*
* @access public
* @param string the table to update data on
- * @return string
+ * @return bool
*/
protected function _validate_update($table = '')
{
if (count($this->ar_set) == 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
{
$this->ar_from[0] = $table;
}
+
+ return TRUE;
}
-
+
// --------------------------------------------------------------------
/**
@@ -1485,7 +1538,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @param string the table to retrieve the results from
* @param array an associative array of update values
* @param string the where key
- * @return object
+ * @return bool
*/
public function update_batch($table = '', $set = NULL, $index = NULL)
{
@@ -1494,12 +1547,7 @@ class CI_DB_active_record extends CI_DB_driver {
if (is_null($index))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_index');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
}
if ( ! is_null($set))
@@ -1507,39 +1555,29 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set_update_batch($set, $index);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+ for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
- $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
-
- $this->query($sql);
+ $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where));
}
$this->_reset_write();
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -1565,7 +1603,6 @@ class CI_DB_active_record extends CI_DB_driver {
{
$index_set = FALSE;
$clean = array();
-
foreach ($v as $k2 => $v2)
{
if ($k2 == $index)
@@ -1577,14 +1614,7 @@ class CI_DB_active_record extends CI_DB_driver {
$not[] = $k.'-'.$v;
}
- if ($escape === FALSE)
- {
- $clean[$this->_protect_identifiers($k2)] = $v2;
- }
- else
- {
- $clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
- }
+ $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
}
if ($index_set == FALSE)
@@ -1614,11 +1644,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1629,9 +1655,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_delete($table);
-
$this->_reset_write();
-
return $this->query($sql);
}
@@ -1653,11 +1677,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1668,12 +1688,10 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_truncate($table);
-
$this->_reset_write();
-
return $this->query($sql);
}
-
+
// --------------------------------------------------------------------
/**
@@ -1693,7 +1711,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->return_delete_sql = FALSE;
return $sql;
}
-
+
// --------------------------------------------------------------------
/**
@@ -1716,11 +1734,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1750,31 +1764,20 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit);
}
- if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
+ if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_del_must_use_where');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE;
}
$sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
-
if ($reset_data)
{
$this->_reset_write();
}
-
- if ($this->return_delete_sql === true)
- {
- return $sql;
- }
- return $this->query($sql);
+ return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql);
}
-
+
// --------------------------------------------------------------------
/**
@@ -1839,13 +1842,13 @@ class CI_DB_active_record extends CI_DB_driver {
}
// if a table alias is used we can recognize it by a space
- if (strpos($table, " ") !== FALSE)
+ if (strpos($table, ' ') !== FALSE)
{
// if the alias is written with the AS keyword, remove it
$table = preg_replace('/ AS /i', ' ', $table);
// Grab the alias
- $table = trim(strrchr($table, " "));
+ $table = trim(strrchr($table, ' '));
// Store the alias, if it doesn't already exist
if ( ! in_array($table, $this->ar_aliased_tables))
@@ -1854,7 +1857,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -1870,10 +1873,7 @@ class CI_DB_active_record extends CI_DB_driver {
// Combine any cached components with the current statements
$this->_merge_cache();
- // ----------------------------------------------------------------
-
// Write the "select" portion of the query
-
if ($select_override !== FALSE)
{
$sql = $select_override;
@@ -1882,7 +1882,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
- if (count($this->ar_select) == 0)
+ if (count($this->ar_select) === 0)
{
$sql .= '*';
}
@@ -1901,32 +1901,19 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- // ----------------------------------------------------------------
-
// Write the "FROM" portion of the query
-
if (count($this->ar_from) > 0)
{
- $sql .= "\nFROM ";
-
- $sql .= $this->_from_tables($this->ar_from);
+ $sql .= "\nFROM ".$this->_from_tables($this->ar_from);
}
- // ----------------------------------------------------------------
-
// Write the "JOIN" portion of the query
-
if (count($this->ar_join) > 0)
{
- $sql .= "\n";
-
- $sql .= implode("\n", $this->ar_join);
+ $sql .= "\n".implode("\n", $this->ar_join);
}
- // ----------------------------------------------------------------
-
// Write the "WHERE" portion of the query
-
if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
{
$sql .= "\nWHERE ";
@@ -1934,10 +1921,7 @@ class CI_DB_active_record extends CI_DB_driver {
$sql .= implode("\n", $this->ar_where);
- // ----------------------------------------------------------------
-
// Write the "LIKE" portion of the query
-
if (count($this->ar_like) > 0)
{
if (count($this->ar_where) > 0)
@@ -1948,50 +1932,32 @@ class CI_DB_active_record extends CI_DB_driver {
$sql .= implode("\n", $this->ar_like);
}
- // ----------------------------------------------------------------
-
// Write the "GROUP BY" portion of the query
-
if (count($this->ar_groupby) > 0)
{
- $sql .= "\nGROUP BY ";
-
- $sql .= implode(', ', $this->ar_groupby);
+ $sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby);
}
- // ----------------------------------------------------------------
-
// Write the "HAVING" portion of the query
-
if (count($this->ar_having) > 0)
{
- $sql .= "\nHAVING ";
- $sql .= implode("\n", $this->ar_having);
+ $sql .= "\nHAVING ".implode("\n", $this->ar_having);
}
- // ----------------------------------------------------------------
-
// Write the "ORDER BY" portion of the query
-
if (count($this->ar_orderby) > 0)
{
- $sql .= "\nORDER BY ";
- $sql .= implode(', ', $this->ar_orderby);
-
+ $sql .= "\nORDER BY ".implode(', ', $this->ar_orderby);
if ($this->ar_order !== FALSE)
{
$sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
}
}
- // ----------------------------------------------------------------
-
// Write the "LIMIT" portion of the query
-
if (is_numeric($this->ar_limit))
{
- $sql .= "\n";
- $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
+ return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset);
}
return $sql;
@@ -2051,14 +2017,12 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($fields as $val)
{
// There are some built in keys we need to ignore for this conversion
- if ($val != '_parent_name')
+ if ($val !== '_parent_name')
{
-
$i = 0;
foreach ($out[$val] as $data)
{
- $array[$i][$val] = $data;
- $i++;
+ $array[$i++][$val] = $data;
}
}
}
@@ -2133,7 +2097,7 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _merge_cache()
{
- if (count($this->ar_cache_exists) == 0)
+ if (count($this->ar_cache_exists) === 0)
{
return;
}
@@ -2143,7 +2107,7 @@ class CI_DB_active_record extends CI_DB_driver {
$ar_variable = 'ar_'.$val;
$ar_cache_var = 'ar_cache_'.$val;
- if (count($this->$ar_cache_var) == 0)
+ if (count($this->$ar_cache_var) === 0)
{
continue;
}
@@ -2160,15 +2124,14 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_no_escape = $this->ar_cache_no_escape;
}
-
+
// --------------------------------------------------------------------
/**
* Reset Active Record values.
- *
+ *
* Publicly-visible method to reset the AR values.
*
- * @access public
* @return void
*/
public function reset_query()
@@ -2205,25 +2168,24 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _reset_select()
{
- $ar_reset_items = array(
- 'ar_select' => array(),
- 'ar_from' => array(),
- 'ar_join' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_groupby' => array(),
- 'ar_having' => array(),
- 'ar_orderby' => array(),
- 'ar_wherein' => array(),
- 'ar_aliased_tables' => array(),
- 'ar_no_escape' => array(),
- 'ar_distinct' => FALSE,
- 'ar_limit' => FALSE,
- 'ar_offset' => FALSE,
- 'ar_order' => FALSE,
- );
-
- $this->_reset_run($ar_reset_items);
+ $this->_reset_run(array(
+ 'ar_select' => array(),
+ 'ar_from' => array(),
+ 'ar_join' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_groupby' => array(),
+ 'ar_having' => array(),
+ 'ar_orderby' => array(),
+ 'ar_wherein' => array(),
+ 'ar_aliased_tables' => array(),
+ 'ar_no_escape' => array(),
+ 'ar_distinct' => FALSE,
+ 'ar_limit' => FALSE,
+ 'ar_offset' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
// --------------------------------------------------------------------
@@ -2237,20 +2199,20 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _reset_write()
{
- $ar_reset_items = array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
- );
-
- $this->_reset_run($ar_reset_items);
+ $this->_reset_run(array(
+ 'ar_set' => array(),
+ 'ar_from' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_orderby' => array(),
+ 'ar_keys' => array(),
+ 'ar_limit' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
+
}
/* End of file DB_active_rec.php */
-/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file
+/* Location: ./system/database/DB_active_rec.php */
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 6c1ffc0f3..79651fcb0 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Cache Class
*
@@ -36,19 +34,12 @@
*/
class CI_DB_Cache {
- var $CI;
- var $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
+ public $CI;
+ public $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
- /**
- * Constructor
- *
- * Grabs the CI super object instance so we can access it.
- *
- */
- function __construct(&$db)
+ public function __construct(&$db)
{
- // Assign the main CI object to $this->CI
- // and load the file helper since we use it a lot
+ // Assign the main CI object to $this->CI and load the file helper since we use it a lot
$this->CI =& get_instance();
$this->db =& $db;
$this->CI->load->helper('file');
@@ -59,11 +50,10 @@ class CI_DB_Cache {
/**
* Set Cache Directory Path
*
- * @access public
* @param string the path to the cache directory
* @return bool
*/
- function check_path($path = '')
+ public function check_path($path = '')
{
if ($path == '')
{
@@ -76,7 +66,7 @@ class CI_DB_Cache {
}
// Add a trailing slash to the path if needed
- $path = preg_replace("/(.+?)\/*$/", "\\1/", $path);
+ $path = preg_replace('/(.+?)\/*$/', '\\1/', $path);
if ( ! is_dir($path) OR ! is_really_writable($path))
{
@@ -96,10 +86,9 @@ class CI_DB_Cache {
* The URI being requested will become the name of the cache sub-folder.
* An MD5 hash of the SQL statement will become the cache file name
*
- * @access public
* @return string
*/
- function read($sql)
+ public function read($sql)
{
if ( ! $this->check_path())
{
@@ -107,9 +96,7 @@ class CI_DB_Cache {
}
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
-
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
-
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
if (FALSE === ($cachedata = read_file($filepath)))
@@ -125,10 +112,9 @@ class CI_DB_Cache {
/**
* Write a query to a cache file
*
- * @access public
* @return bool
*/
- function write($sql, $object)
+ public function write($sql, $object)
{
if ( ! $this->check_path())
{
@@ -136,11 +122,8 @@ class CI_DB_Cache {
}
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
-
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
-
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
-
$filename = md5($sql);
if ( ! @is_dir($dir_path))
@@ -167,10 +150,9 @@ class CI_DB_Cache {
/**
* Delete cache files within a particular directory
*
- * @access public
* @return bool
*/
- function delete($segment_one = '', $segment_two = '')
+ public function delete($segment_one = '', $segment_two = '')
{
if ($segment_one == '')
{
@@ -183,7 +165,6 @@ class CI_DB_Cache {
}
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
-
delete_files($dir_path, TRUE);
}
@@ -192,16 +173,14 @@ class CI_DB_Cache {
/**
* Delete all existing cache files
*
- * @access public
* @return bool
*/
- function delete_all()
+ public function delete_all()
{
delete_files($this->db->cachedir, TRUE);
}
}
-
/* End of file DB_cache.php */
-/* Location: ./system/database/DB_cache.php */ \ No newline at end of file
+/* Location: ./system/database/DB_cache.php */
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 9d92f2f87..6352c731e 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -81,8 +81,7 @@ class CI_DB_driver {
var $stmt_id;
var $curs_id;
var $limit_used;
-
-
+
/**
* Constructor. Accepts one parameter containing the database
@@ -108,11 +107,9 @@ class CI_DB_driver {
/**
* Initialize Database Settings
*
- * @access private Called by the constructor
- * @param mixed
- * @return void
+ * @return bool
*/
- function initialize()
+ public function initialize()
{
// If an existing connection resource is available
// there is no need to connect and select the database
@@ -126,7 +123,7 @@ class CI_DB_driver {
// Connect to the database and set the connection ID
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
- // No connection resource? Check if there is a failover else throw an error
+ // No connection resource? Check if there is a failover else throw an error
if ( ! $this->conn_id)
{
// Check if there is a failover set
@@ -168,31 +165,19 @@ class CI_DB_driver {
// ----------------------------------------------------------------
// Select the DB... assuming a database name is specified in the config file
- if ($this->database != '')
+ if ($this->database !== '' && ! $this->db_select())
{
- if ( ! $this->db_select())
- {
- log_message('error', 'Unable to select database: '.$this->database);
+ log_message('error', 'Unable to select database: '.$this->database);
- if ($this->db_debug)
- {
- $this->display_error('db_unable_to_select', $this->database);
- }
- return FALSE;
- }
- else
+ if ($this->db_debug)
{
- // We've selected the DB. Now we set the character set
- if ( ! $this->db_set_charset($this->char_set, $this->dbcollat))
- {
- return FALSE;
- }
-
- return TRUE;
+ $this->display_error('db_unable_to_select', $this->database);
}
+ return FALSE;
}
- return TRUE;
+ // Now we set the character set and that's all
+ return $this->db_set_charset($this->char_set, $this->dbcollat);
}
// --------------------------------------------------------------------
@@ -257,7 +242,7 @@ class CI_DB_driver {
// Some DBs have functions that return the version, and don't run special
// SQL queries per se. In these instances, just return the result.
- $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo');
+ $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo', 'mysqli');
if (in_array($this->dbdriver, $driver_version_exceptions))
{
@@ -814,20 +799,23 @@ class CI_DB_driver {
if ($query->num_rows() > 0)
{
- foreach ($query->result_array() as $row)
+ $table = FALSE;
+ $rows = $query->result_array();
+ $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row))));
+
+ if ($key)
{
- if (isset($row['TABLE_NAME']))
- {
- $retval[] = $row['TABLE_NAME'];
- }
- else
- {
- $retval[] = array_shift($row);
- }
+ $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name';
+ }
+
+ foreach ($rows as $row)
+ {
+ $retval[] = ( ! $table) ? current($row) : $row[$table];
}
}
$this->data_cache['table_names'] = $retval;
+
return $this->data_cache['table_names'];
}
@@ -1436,10 +1424,23 @@ class CI_DB_driver {
return $item.$alias;
}
+
+ // --------------------------------------------------------------------
+ /**
+ * Dummy method that allows Active Record class to be disabled
+ *
+ * This function is used extensively by every db driver.
+ *
+ * @access private
+ * @return void
+ */
+ protected function _reset_select()
+ {
+
+ }
}
-
/* End of file DB_driver.php */
-/* Location: ./system/database/DB_driver.php */
+/* Location: ./system/database/DB_driver.php */ \ No newline at end of file
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 78bf77a9f..336e9497d 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -36,23 +36,17 @@
*/
class CI_DB_forge {
- var $fields = array();
- var $keys = array();
- var $primary_keys = array();
- var $db_char_set = '';
+ public $fields = array();
+ public $keys = array();
+ public $primary_keys = array();
+ public $db_char_set = '';
- /**
- * Constructor
- *
- * Grabs the CI super object instance so we can access it.
- *
- */
- function __construct()
+ public function __construct()
{
// Assign the main database object to $this->db
$CI =& get_instance();
$this->db =& $CI->db;
- log_message('debug', "Database Forge Class Initialized");
+ log_message('debug', 'Database Forge Class Initialized');
}
// --------------------------------------------------------------------
@@ -60,20 +54,13 @@ class CI_DB_forge {
/**
* Create database
*
- * @access public
* @param string the database name
* @return bool
*/
- function create_database($db_name)
+ public function create_database($db_name)
{
$sql = $this->_create_database($db_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -81,20 +68,13 @@ class CI_DB_forge {
/**
* Drop database
*
- * @access public
* @param string the database name
* @return bool
*/
- function drop_database($db_name)
+ public function drop_database($db_name)
{
$sql = $this->_drop_database($db_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -102,12 +82,11 @@ class CI_DB_forge {
/**
* Add Key
*
- * @access public
* @param string key
* @param string type
- * @return void
+ * @return object
*/
- function add_key($key = '', $primary = FALSE)
+ public function add_key($key = '', $primary = FALSE)
{
if (is_array($key))
{
@@ -132,6 +111,8 @@ class CI_DB_forge {
{
$this->keys[] = $key;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -139,11 +120,10 @@ class CI_DB_forge {
/**
* Add Field
*
- * @access public
* @param string collation
- * @return void
+ * @return object
*/
- function add_field($field = '')
+ public function add_field($field = '')
{
if ($field == '')
{
@@ -152,15 +132,15 @@ class CI_DB_forge {
if (is_string($field))
{
- if ($field == 'id')
+ if ($field === 'id')
{
$this->add_field(array(
- 'id' => array(
- 'type' => 'INT',
- 'constraint' => 9,
- 'auto_increment' => TRUE
- )
- ));
+ 'id' => array(
+ 'type' => 'INT',
+ 'constraint' => 9,
+ 'auto_increment' => TRUE
+ )
+ ));
$this->add_key('id', TRUE);
}
else
@@ -179,6 +159,7 @@ class CI_DB_forge {
$this->fields = array_merge($this->fields, $field);
}
+ return $this;
}
// --------------------------------------------------------------------
@@ -186,32 +167,24 @@ class CI_DB_forge {
/**
* Create Table
*
- * @access public
* @param string the table name
* @return bool
*/
- function create_table($table = '', $if_not_exists = FALSE)
+ public function create_table($table = '', $if_not_exists = FALSE)
{
if ($table == '')
{
show_error('A table name is required for that operation.');
}
- if (count($this->fields) == 0)
+ if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
$sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
-
$this->_reset();
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -219,20 +192,13 @@ class CI_DB_forge {
/**
* Drop Table
*
- * @access public
* @param string the table name
* @return bool
*/
- function drop_table($table_name)
+ public function drop_table($table_name)
{
$sql = $this->_drop_table($this->db->dbprefix.$table_name);
-
- if (is_bool($sql))
- {
- return $sql;
- }
-
- return $this->db->query($sql);
+ return is_bool($sql) ? $sql : $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -240,20 +206,18 @@ class CI_DB_forge {
/**
* Rename Table
*
- * @access public
* @param string the old table name
* @param string the new table name
* @return bool
*/
- function rename_table($table_name, $new_table_name)
+ public function rename_table($table_name, $new_table_name)
{
if ($table_name == '' OR $new_table_name == '')
{
show_error('A table name is required for that operation.');
}
- $sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name);
- return $this->db->query($sql);
+ return $this->db->query($this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name));
}
// --------------------------------------------------------------------
@@ -261,13 +225,12 @@ class CI_DB_forge {
/**
* Column Add
*
- * @access public
* @param string the table name
* @param string the column name
* @param string the column definition
* @return bool
*/
- function add_column($table = '', $field = array(), $after_field = '')
+ public function add_column($table = '', $field = array(), $after_field = '')
{
if ($table == '')
{
@@ -276,8 +239,7 @@ class CI_DB_forge {
// add field info into field array, but we can only do one at a time
// so we cycle through
-
- foreach ($field as $k => $v)
+ foreach (array_keys($field) as $k)
{
$this->add_field(array($k => $field[$k]));
@@ -287,7 +249,6 @@ class CI_DB_forge {
}
$sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
-
$this->_reset();
if ($this->db->query($sql) === FALSE)
@@ -297,7 +258,6 @@ class CI_DB_forge {
}
return TRUE;
-
}
// --------------------------------------------------------------------
@@ -305,14 +265,12 @@ class CI_DB_forge {
/**
* Column Drop
*
- * @access public
* @param string the table name
* @param string the column name
* @return bool
*/
- function drop_column($table = '', $column_name = '')
+ public function drop_column($table = '', $column_name = '')
{
-
if ($table == '')
{
show_error('A table name is required for that operation.');
@@ -323,9 +281,7 @@ class CI_DB_forge {
show_error('A column name is required for that operation.');
}
- $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
-
- return $this->db->query($sql);
+ return $this->db->query($this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name));
}
// --------------------------------------------------------------------
@@ -333,13 +289,12 @@ class CI_DB_forge {
/**
* Column Modify
*
- * @access public
* @param string the table name
* @param string the column name
* @param string the column definition
* @return bool
*/
- function modify_column($table = '', $field = array())
+ public function modify_column($table = '', $field = array())
{
if ($table == '')
{
@@ -348,8 +303,7 @@ class CI_DB_forge {
// add field info into field array, but we can only do one at a time
// so we cycle through
-
- foreach ($field as $k => $v)
+ foreach (array_keys($field) as $k)
{
// If no name provided, use the current name
if ( ! isset($field[$k]['name']))
@@ -358,14 +312,12 @@ class CI_DB_forge {
}
$this->add_field(array($k => $field[$k]));
-
- if (count($this->fields) == 0)
+ if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
$sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
-
$this->_reset();
if ($this->db->query($sql) === FALSE)
@@ -384,17 +336,14 @@ class CI_DB_forge {
*
* Resets table creation vars
*
- * @access private
* @return void
*/
- function _reset()
+ protected function _reset()
{
- $this->fields = array();
- $this->keys = array();
- $this->primary_keys = array();
+ $this->fields = $this->keys = $this->primary_keys = array();
}
}
/* End of file DB_forge.php */
-/* Location: ./system/database/DB_forge.php */ \ No newline at end of file
+/* Location: ./system/database/DB_forge.php */
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 9f0b0187c..730443222 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Result Class
*
@@ -40,27 +38,25 @@
*/
class CI_DB_result {
- var $conn_id = NULL;
- var $result_id = NULL;
- var $result_array = array();
- var $result_object = array();
- var $custom_result_object = array();
- var $current_row = 0;
- var $num_rows = 0;
- var $row_data = NULL;
-
+ public $conn_id = NULL;
+ public $result_id = NULL;
+ public $result_array = array();
+ public $result_object = array();
+ public $custom_result_object = array();
+ public $current_row = 0;
+ public $num_rows = 0;
+ public $row_data = NULL;
/**
* Query result. Acts as a wrapper function for the following functions.
*
- * @access public
* @param string can be "object" or "array"
* @return mixed either a result object or array
*/
public function result($type = 'object')
{
- if ($type == 'array') return $this->result_array();
- else if ($type == 'object') return $this->result_object();
+ if ($type === 'array') return $this->result_array();
+ elseif ($type === 'object') return $this->result_object();
else return $this->custom_result_object($type);
}
@@ -69,8 +65,8 @@ class CI_DB_result {
/**
* Custom query result.
*
- * @param class_name A string that represents the type of object you want back
- * @return array of objects
+ * @param string A string that represents the type of object you want back
+ * @return array of objects
*/
public function custom_result_object($class_name)
{
@@ -91,7 +87,6 @@ class CI_DB_result {
while ($row = $this->_fetch_object())
{
$object = new $class_name();
-
foreach ($row as $key => $value)
{
$object->$key = $value;
@@ -109,7 +104,6 @@ class CI_DB_result {
/**
* Query result. "object" version.
*
- * @access public
* @return object
*/
public function result_object()
@@ -141,7 +135,6 @@ class CI_DB_result {
/**
* Query result. "array" version.
*
- * @access public
* @return array
*/
public function result_array()
@@ -173,7 +166,6 @@ class CI_DB_result {
/**
* Query result. Acts as a wrapper function for the following functions.
*
- * @access public
* @param string
* @param string can be "object" or "array"
* @return mixed either a result object or array
@@ -197,8 +189,8 @@ class CI_DB_result {
$n = 0;
}
- if ($type == 'object') return $this->row_object($n);
- else if ($type == 'array') return $this->row_array($n);
+ if ($type === 'object') return $this->row_object($n);
+ elseif ($type === 'array') return $this->row_array($n);
else return $this->custom_row_object($n, $type);
}
@@ -207,8 +199,7 @@ class CI_DB_result {
/**
* Assigns an item into a particular column slot
*
- * @access public
- * @return object
+ * @return void
*/
public function set_row($key, $value = NULL)
{
@@ -224,7 +215,6 @@ class CI_DB_result {
{
$this->row_data[$k] = $v;
}
-
return;
}
@@ -239,14 +229,12 @@ class CI_DB_result {
/**
* Returns a single result row - custom object version
*
- * @access public
* @return object
*/
public function custom_row_object($n, $type)
{
$result = $this->custom_result_object($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -262,14 +250,12 @@ class CI_DB_result {
/**
* Returns a single result row - object version
*
- * @access public
* @return object
*/
public function row_object($n = 0)
{
$result = $this->result_object();
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -287,14 +273,12 @@ class CI_DB_result {
/**
* Returns a single result row - array version
*
- * @access public
* @return array
*/
public function row_array($n = 0)
{
$result = $this->result_array();
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -313,18 +297,12 @@ class CI_DB_result {
/**
* Returns the "first" row
*
- * @access public
* @return object
*/
public function first_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
- {
- return $result;
- }
- return $result[0];
+ return (count($result) === 0) ? $result : $result[0];
}
// --------------------------------------------------------------------
@@ -332,18 +310,12 @@ class CI_DB_result {
/**
* Returns the "last" row
*
- * @access public
* @return object
*/
public function last_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
- {
- return $result;
- }
- return $result[count($result) -1];
+ return (count($result) === 0) ? $result : $result[count($result) - 1];
}
// --------------------------------------------------------------------
@@ -351,14 +323,12 @@ class CI_DB_result {
/**
* Returns the "next" row
*
- * @access public
* @return object
*/
public function next_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -376,14 +346,12 @@ class CI_DB_result {
/**
* Returns the "previous" row
*
- * @access public
* @return object
*/
public function previous_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -416,7 +384,6 @@ class CI_DB_result {
protected function _fetch_object() { return array(); }
}
-// END DB_result class
/* End of file DB_result.php */
/* Location: ./system/database/DB_result.php */
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 60ecb5269..4c881d8a1 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Database Utility Class
*
@@ -36,22 +34,15 @@
*/
class CI_DB_utility extends CI_DB_forge {
- var $db;
- var $data_cache = array();
+ public $db;
+ public $data_cache = array();
- /**
- * Constructor
- *
- * Grabs the CI super object instance so we can access it.
- *
- */
- function __construct()
+ public function __construct()
{
// Assign the main database object to $this->db
$CI =& get_instance();
$this->db =& $CI->db;
-
- log_message('debug', "Database Utility Class Initialized");
+ log_message('debug', 'Database Utility Class Initialized');
}
// --------------------------------------------------------------------
@@ -59,10 +50,9 @@ class CI_DB_utility extends CI_DB_forge {
/**
* List databases
*
- * @access public
* @return bool
*/
- function list_databases()
+ public function list_databases()
{
// Is there a cached result?
if (isset($this->data_cache['db_names']))
@@ -80,8 +70,7 @@ class CI_DB_utility extends CI_DB_forge {
}
}
- $this->data_cache['db_names'] = $dbs;
- return $this->data_cache['db_names'];
+ return $this->data_cache['db_names'] = $dbs;
}
// --------------------------------------------------------------------
@@ -89,11 +78,10 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Determine if a particular database exists
*
- * @access public
* @param string
* @return boolean
*/
- function database_exists($database_name)
+ public function database_exists($database_name)
{
// Some databases won't have access to the list_databases() function, so
// this is intended to allow them to override with their own functions as
@@ -114,17 +102,17 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Table
*
- * @access public
* @param string the table name
* @return bool
*/
- function optimize_table($table_name)
+ public function optimize_table($table_name)
{
$sql = $this->_optimize_table($table_name);
if (is_bool($sql))
{
- show_error('db_must_use_set');
+ show_error('db_must_use_set');
+ return FALSE;
}
$query = $this->db->query($sql);
@@ -140,10 +128,9 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Database
*
- * @access public
* @return array
*/
- function optimize_database()
+ public function optimize_database()
{
$result = array();
foreach ($this->db->list_tables() as $table_name)
@@ -177,11 +164,10 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Repair Table
*
- * @access public
* @param string the table name
* @return bool
*/
- function repair_table($table_name)
+ public function repair_table($table_name)
{
$sql = $this->_repair_table($table_name);
@@ -203,14 +189,13 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Generate CSV from a query result object
*
- * @access public
* @param object The query result object
* @param string The delimiter - comma by default
* @param string The newline character - \n by default
* @param string The enclosure - double quote by default
* @return string
*/
- function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"')
+ public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
{
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
{
@@ -218,15 +203,13 @@ class CI_DB_utility extends CI_DB_forge {
}
$out = '';
-
// First generate the headings from the table column names
foreach ($query->list_fields() as $name)
{
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
}
- $out = rtrim($out);
- $out .= $newline;
+ $out = rtrim($out).$newline;
// Next blast through the result array and build out the rows
foreach ($query->result_array() as $row)
@@ -235,8 +218,7 @@ class CI_DB_utility extends CI_DB_forge {
{
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
}
- $out = rtrim($out);
- $out .= $newline;
+ $out = rtrim($out).$newline;
}
return $out;
@@ -247,12 +229,11 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Generate XML data from a query result object
*
- * @access public
* @param object The query result object
* @param array Any preferences
* @return string
*/
- function xml_from_result($query, $params = array())
+ public function xml_from_result($query, $params = array())
{
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
{
@@ -280,16 +261,14 @@ class CI_DB_utility extends CI_DB_forge {
foreach ($query->result_array() as $row)
{
$xml .= $tab."<{$element}>".$newline;
-
foreach ($row as $key => $val)
{
$xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline;
}
$xml .= $tab."</{$element}>".$newline;
}
- $xml .= "</$root>".$newline;
- return $xml;
+ return $xml .= "</$root>".$newline;
}
// --------------------------------------------------------------------
@@ -297,10 +276,9 @@ class CI_DB_utility extends CI_DB_forge {
/**
* Database Backup
*
- * @access public
* @return void
*/
- function backup($params = array())
+ public function backup($params = array())
{
// If the parameters have not been submitted as an
// array then we know that it is simply the table
@@ -314,14 +292,14 @@ class CI_DB_utility extends CI_DB_forge {
// Set up our default preferences
$prefs = array(
- 'tables' => array(),
- 'ignore' => array(),
- 'filename' => '',
- 'format' => 'gzip', // gzip, zip, txt
- 'add_drop' => TRUE,
- 'add_insert' => TRUE,
- 'newline' => "\n"
- );
+ 'tables' => array(),
+ 'ignore' => array(),
+ 'filename' => '',
+ 'format' => 'gzip', // gzip, zip, txt
+ 'add_drop' => TRUE,
+ 'add_insert' => TRUE,
+ 'newline' => "\n"
+ );
// Did the user submit any preferences? If so set them....
if (count($params) > 0)
@@ -335,29 +313,23 @@ class CI_DB_utility extends CI_DB_forge {
}
}
- // ------------------------------------------------------
-
// Are we backing up a complete database or individual tables?
// If no table names were submitted we'll fetch the entire table list
- if (count($prefs['tables']) == 0)
+ if (count($prefs['tables']) === 0)
{
$prefs['tables'] = $this->db->list_tables();
}
- // ------------------------------------------------------
-
// Validate the format
if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
{
$prefs['format'] = 'txt';
}
- // ------------------------------------------------------
-
- // Is the encoder supported? If not, we'll either issue an
+ // Is the encoder supported? If not, we'll either issue an
// error or use plain text depending on the debug settings
- if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode'))
- OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress')))
+ if (($prefs['format'] === 'gzip' AND ! @function_exists('gzencode'))
+ OR ($prefs['format'] === 'zip' AND ! @function_exists('gzcompress')))
{
if ($this->db->db_debug)
{
@@ -367,60 +339,49 @@ class CI_DB_utility extends CI_DB_forge {
$prefs['format'] = 'txt';
}
- // ------------------------------------------------------
-
- // Set the filename if not provided - Only needed with Zip files
- if ($prefs['filename'] == '' AND $prefs['format'] == 'zip')
- {
- $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database;
- $prefs['filename'] .= '_'.date('Y-m-d_H-i', time());
- }
-
- // ------------------------------------------------------
-
- // Was a Gzip file requested?
- if ($prefs['format'] == 'gzip')
- {
- return gzencode($this->_backup($prefs));
- }
-
- // ------------------------------------------------------
-
- // Was a text file requested?
- if ($prefs['format'] == 'txt')
- {
- return $this->_backup($prefs);
- }
-
- // ------------------------------------------------------
-
// Was a Zip file requested?
- if ($prefs['format'] == 'zip')
+ if ($prefs['format'] === 'zip')
{
- // If they included the .zip file extension we'll remove it
- if (preg_match("|.+?\.zip$|", $prefs['filename']))
+ // Set the filename if not provided (only needed with Zip files)
+ if ($prefs['filename'] == '')
{
- $prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
+ $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
+ .date('Y-m-d_H-i', time()).'.sql';
}
-
- // Tack on the ".sql" file extension if needed
- if ( ! preg_match("|.+?\.sql$|", $prefs['filename']))
+ else
{
- $prefs['filename'] .= '.sql';
+ // If they included the .zip file extension we'll remove it
+ if (preg_match('|.+?\.zip$|', $prefs['filename']))
+ {
+ $prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
+ }
+
+ // Tack on the ".sql" file extension if needed
+ if ( ! preg_match('|.+?\.sql$|', $prefs['filename']))
+ {
+ $prefs['filename'] .= '.sql';
+ }
}
// Load the Zip class and output it
-
$CI =& get_instance();
$CI->load->library('zip');
$CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
return $CI->zip->get_zip();
}
+ elseif ($prefs['format'] == 'txt') // Was a text file requested?
+ {
+ return $this->_backup($prefs);
+ }
+ elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested?
+ {
+ return gzencode($this->_backup($prefs));
+ }
+ return;
}
}
-
/* End of file DB_utility.php */
-/* Location: ./system/database/DB_utility.php */ \ No newline at end of file
+/* Location: ./system/database/DB_utility.php */
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 8181bd605..cde719eae 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0.2
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 410d0652c..85e740057 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index b2f1bcf71..4c0fede10 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0.2
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index 1fa0390a8..750c0d8dd 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 87e7c9d37..25a32f364 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -114,14 +114,25 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
// Note: The brackets are required in the event that the DB name
// contains reserved characters
- return @mssql_select_db('['.$this->database.']', $this->conn_id);
+ if (@mssql_select_db('['.$database.']', $this->conn_id))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -676,4 +687,4 @@ class CI_DB_mssql_driver extends CI_DB {
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 0a893f68f..dd8aa3448 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index a8cd7c982..bba2e6243 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index 576d13f86..be6ed5bb0 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 6ded6e531..c88a8a766 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQL Database Adapter Class
*
@@ -42,46 +40,47 @@
*/
class CI_DB_mysql_driver extends CI_DB {
- var $dbdriver = 'mysql';
+ public $dbdriver = 'mysql';
// The character used for escaping
- var $_escape_char = '`';
+ protected $_escape_char = '`';
// clause and character used for LIKE escape sequences - not used in MySQL
- var $_like_escape_str = '';
- var $_like_escape_chr = '';
-
- /**
- * Whether to use the MySQL "delete hack" which allows the number
- * of affected rows to be shown. Uses a preg_replace when enabled,
- * adding a bit more processing to all queries.
- */
- var $delete_hack = TRUE;
+ protected $_like_escape_str = '';
+ protected $_like_escape_chr = '';
/**
* 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.
*/
- var $_count_string = 'SELECT COUNT(*) AS ';
- var $_random_keyword = ' RAND()'; // database specific random keyword
-
- // whether SET NAMES must be used to set the character set
- var $use_set_names;
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
- * Non-persistent database connection
- *
- * @access private called by the base class
- * @return resource
+ * Whether to use the MySQL "delete hack" which allows the number
+ * of affected rows to be shown. Uses a preg_replace when enabled,
+ * adding a bit more processing to all queries.
*/
- function db_connect()
+ public $delete_hack = TRUE;
+
+ public function __construct($params)
{
+ parent::__construct($params);
+
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}
+ }
+ /**
+ * Non-persistent database connection
+ *
+ * @return resource
+ */
+ public function db_connect()
+ {
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
}
@@ -90,16 +89,10 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
- if ($this->port != '')
- {
- $this->hostname .= ':'.$this->port;
- }
-
return @mysql_pconnect($this->hostname, $this->username, $this->password);
}
@@ -111,10 +104,9 @@ class CI_DB_mysql_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (mysql_ping($this->conn_id) === FALSE)
{
@@ -127,12 +119,23 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return @mysql_select_db($this->database, $this->conn_id);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if (@mysql_select_db($database, $this->conn_id))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -140,12 +143,11 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
return function_exists('mysql_set_charset')
? @mysql_set_charset($charset, $this->conn_id)
@@ -157,12 +159,11 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT version() AS ver";
+ return 'SELECT version() AS ver';
}
// --------------------------------------------------------------------
@@ -170,14 +171,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return resource
+ * @return mixed
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return @mysql_query($sql, $this->conn_id);
+ return @mysql_query($this->_prep_query($sql), $this->conn_id);
}
// --------------------------------------------------------------------
@@ -187,20 +186,16 @@ class CI_DB_mysql_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
- // "DELETE FROM TABLE" returns 0 affected rows This hack modifies
- // the query so that it returns the number of affected rows
- if ($this->delete_hack === TRUE)
+ // 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))
{
- if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
- {
- $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
- }
+ return preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql);
}
return $sql;
@@ -211,18 +206,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -230,7 +219,7 @@ class CI_DB_mysql_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
$this->simple_query('SET AUTOCOMMIT=0');
$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
@@ -242,18 +231,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -268,18 +251,12 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -294,12 +271,11 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -311,7 +287,7 @@ class CI_DB_mysql_driver extends CI_DB {
return $str;
}
- if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id))
+ if (function_exists('mysql_real_escape_string') && is_resource($this->conn_id))
{
$str = mysql_real_escape_string($str, $this->conn_id);
}
@@ -327,7 +303,7 @@ class CI_DB_mysql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
@@ -338,10 +314,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mysql_affected_rows($this->conn_id);
}
@@ -351,10 +326,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @mysql_insert_id($this->conn_id);
}
@@ -367,27 +341,25 @@ class CI_DB_mysql_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -397,17 +369,16 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
+ $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char;
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
@@ -420,13 +391,12 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ public function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -436,13 +406,12 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ public function _field_data($table)
{
- return "DESCRIBE ".$table;
+ return 'DESCRIBE '.$table;
}
// --------------------------------------------------------------------
@@ -450,10 +419,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return mysql_error($this->conn_id);
}
@@ -463,10 +431,9 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return mysql_errno($this->conn_id);
}
@@ -478,11 +445,10 @@ class CI_DB_mysql_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -493,24 +459,20 @@ class CI_DB_mysql_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -521,11 +483,10 @@ class CI_DB_mysql_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param string table name
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -542,15 +503,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -561,15 +521,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
- return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -579,15 +538,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -598,7 +556,6 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -606,34 +563,22 @@ class CI_DB_mysql_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
{
foreach ($values as $key => $val)
{
- $valstr[] = $key . ' = ' . $val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- if (count($like) > 0)
+ $where = ($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '';
+ if (count($like) > 0)
{
- $sql .= ($where == '' AND count($where) <1) ? " WHERE " : ' AND ';
-
- foreach ($like as $st_like)
- {
- $sql .= " " . $st_like;
- }
+ $where .= ($where == '' ? ' WHERE ' : ' AND ').implode(' ', $like);
}
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -644,17 +589,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
-
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
@@ -668,30 +610,21 @@ class CI_DB_mysql_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
$cases = '';
-
foreach ($final as $k => $v)
{
- $cases .= $k.' = CASE '."\n";
- foreach ($v as $row)
- {
- $cases .= $row."\n";
- }
-
- $cases .= 'ELSE '.$k.' END, ';
+ $cases .= $k." = CASE \n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END, ';
}
- $sql .= substr($cases, 0, -2);
-
- $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
-
/**
* Truncate statement
*
@@ -699,13 +632,12 @@ class CI_DB_mysql_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -715,31 +647,27 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -749,24 +677,14 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
-
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.' LIMIT '.($offset == 0 ? '' : $offset.', ').$limit;
}
// --------------------------------------------------------------------
@@ -774,17 +692,15 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mysql_close($conn_id);
}
}
-
/* End of file mysql_driver.php */
-/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_driver.php */
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 89aaf5de3..0f251b086 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQL Forge Class
*
@@ -39,13 +37,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
- return "CREATE DATABASE ".$name;
+ return 'CREATE DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -53,13 +50,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
- return "DROP DATABASE ".$name;
+ return 'DROP DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -67,83 +63,57 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Process Fields
*
- * @access private
* @param mixed the fields
* @return string
*/
- function _process_fields($fields)
+ private function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
- if (array_key_exists('TYPE', $attributes))
+ if ( ! empty($attributes['TYPE']))
{
$sql .= ' '.$attributes['TYPE'];
- if (array_key_exists('CONSTRAINT', $attributes))
+ if ( ! empty($attributes['CONSTRAINT']))
{
- switch ($attributes['TYPE'])
+ switch (strtolower($attributes['TYPE']))
{
case 'decimal':
case 'float':
case 'numeric':
$sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
-
+ break;
case 'enum':
case 'set':
$sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
-
+ break;
default:
$sql .= '('.$attributes['CONSTRAINT'].')';
}
}
}
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= (( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -161,15 +131,14 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -178,15 +147,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields);
if (count($primary_keys) > 0)
{
$key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -204,13 +170,11 @@ class CI_DB_mysql_forge extends CI_DB_forge {
$key = array($key_name);
}
- $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";
-
- return $sql;
+ return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
}
// --------------------------------------------------------------------
@@ -218,12 +182,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
+ * @param string table name
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -232,33 +196,26 @@ class CI_DB_mysql_forge extends CI_DB_forge {
* Alter table query
*
* Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Called by add_column(), drop_column() and column_alter()
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
- return $sql.$this->db->_protect_identifiers($fields);
+ return $sql.$this->db->protect_identifiers($fields);
}
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -268,18 +225,16 @@ class CI_DB_mysql_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file mysql_forge.php */
-/* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_forge.php */
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index 29297b6a4..8f04a936d 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// --------------------------------------------------------------------
-
/**
* MySQL Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @mysql_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mysql_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mysql_fetch_field($this->result_id))
@@ -90,25 +85,21 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
while ($field = mysql_fetch_object($this->result_id))
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
- $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
- $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
-
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = $type;
- $F->default = $field->Default;
- $F->max_length = $length;
- $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
+ $F = new stdClass();
+ $F->name = $field->Field;
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = $field->Default;
+ $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
+ $F->primary_key = (int) ($field->Key === 'PRI');
$retval[] = $F;
}
@@ -121,9 +112,9 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -137,14 +128,13 @@ class CI_DB_mysql_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return mysql_data_seek($this->result_id, $n);
}
@@ -156,10 +146,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mysql_fetch_assoc($this->result_id);
}
@@ -171,16 +160,14 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mysql_fetch_object($this->result_id);
}
}
-
/* End of file mysql_result.php */
-/* Location: ./system/database/drivers/mysql/mysql_result.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_result.php */
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 9cb6645eb..952f887fe 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQL Utility Class
*
@@ -39,12 +37,11 @@ class CI_DB_mysql_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
- return "SHOW DATABASES";
+ return 'SHOW DATABASES';
}
// --------------------------------------------------------------------
@@ -54,13 +51,12 @@ class CI_DB_mysql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
- return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table);
+ return 'OPTIMIZE TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -70,26 +66,24 @@ class CI_DB_mysql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return "REPAIR TABLE ".$this->db->_escape_identifiers($table);
+ return 'REPAIR TABLE '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
/**
* MySQL Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
- if (count($params) == 0)
+ if (count($params) === 0)
{
return FALSE;
}
@@ -99,16 +93,16 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// Build the output
$output = '';
- foreach ((array)$tables as $table)
+ foreach ( (array) $tables as $table)
{
// Is the table in the "ignore" list?
- if (in_array($table, (array)$ignore, TRUE))
+ if (in_array($table, (array) $ignore, TRUE))
{
continue;
}
// Get the table schema
- $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.`'.$table.'`');
+ $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table));
// No result means the table name was invalid
if ($query === FALSE)
@@ -121,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
if ($add_drop == TRUE)
{
- $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
+ $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
}
$i = 0;
@@ -141,7 +135,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Grab all the data from the current table
- $query = $this->db->query("SELECT * FROM $table");
+ $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
if ($query->num_rows() == 0)
{
@@ -149,7 +143,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Fetch the field names and determine if the field is an
- // integer type. We use this info to decide whether to
+ // integer type. We use this info to decide whether to
// surround the data with quotes or not
$i = 0;
@@ -158,20 +152,17 @@ class CI_DB_mysql_utility extends CI_DB_utility {
while ($field = mysql_fetch_field($query->result_id))
{
// Most versions of MySQL store timestamp as a string
- $is_int[$i] = (in_array(
- strtolower(mysql_field_type($query->result_id, $i)),
- array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
- TRUE)
- ) ? TRUE : FALSE;
+ $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)),
+ array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
+ TRUE);
// Create a string of field names
- $field_str .= '`'.$field->name.'`, ';
+ $field_str .= $this->db->protect_identifiers($field->name).', ';
$i++;
}
// Trim off the end comma
- $field_str = preg_replace( "/, $/" , "" , $field_str);
-
+ $field_str = preg_replace('/, $/' , '', $field_str);
// Build the insert string
foreach ($query->result_array() as $row)
@@ -189,14 +180,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
else
{
// Escape the data if it's not an integer
- if ($is_int[$i] == FALSE)
- {
- $val_str .= $this->db->escape($v);
- }
- else
- {
- $val_str .= $v;
- }
+ $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v;
}
// Append a comma
@@ -205,10 +189,10 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Remove the comma at the end of the string
- $val_str = preg_replace( "/, $/" , "" , $val_str);
+ $val_str = preg_replace('/, $/' , '', $val_str);
// Build the INSERT string
- $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
+ $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
}
$output .= $newline.$newline;
@@ -216,7 +200,8 @@ class CI_DB_mysql_utility extends CI_DB_utility {
return $output;
}
+
}
/* End of file mysql_utility.php */
-/* Location: ./system/database/drivers/mysql/mysql_utility.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_utility.php */
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index fb5953bd7..dbba12e15 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,17 +18,15 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
- * MySQLi Database Adapter Class - MySQLi only works with PHP 5
+ * MySQLi Database Adapter Class
*
* Note: _DB is an extender class that the app controller
* creates dynamically based on whether the active record
@@ -42,52 +40,40 @@
*/
class CI_DB_mysqli_driver extends CI_DB {
- var $dbdriver = 'mysqli';
+ public $dbdriver = 'mysqli';
// The character used for escaping
- var $_escape_char = '`';
+ protected $_escape_char = '`';
// clause and character used for LIKE escape sequences - not used in MySQL
- var $_like_escape_str = '';
- var $_like_escape_chr = '';
+ protected $_like_escape_str = '';
+ protected $_like_escape_chr = '';
/**
* 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.
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' RAND()'; // database specific random keyword
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' RAND()'; // database specific random keyword
/**
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
*/
- var $delete_hack = TRUE;
-
- // whether SET NAMES must be used to set the character set
- var $use_set_names;
-
- // --------------------------------------------------------------------
+ public $delete_hack = TRUE;
/**
* Non-persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_connect()
+ public function db_connect()
{
- if ($this->port != '')
- {
- return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
- }
- else
- {
- return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
- }
-
+ return ($this->port != '')
+ ? @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port)
+ : @mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
}
// --------------------------------------------------------------------
@@ -95,12 +81,19 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
- * @return resource
+ * @return object
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return $this->db_connect();
+ // Persistent connection support was added in PHP 5.3.0
+ if ( ! is_php('5.3'))
+ {
+ return $this->db_connect();
+ }
+
+ return ($this->port != '')
+ ? @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port)
+ : @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database);
}
// --------------------------------------------------------------------
@@ -111,10 +104,9 @@ class CI_DB_mysqli_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (mysqli_ping($this->conn_id) === FALSE)
{
@@ -127,12 +119,23 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return @mysqli_select_db($this->conn_id, $this->database);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if (@mysqli_select_db($this->conn_id, $database))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -140,12 +143,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Set client character set
*
- * @access private
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function _db_set_charset($charset, $collation)
+ protected function _db_set_charset($charset, $collation)
{
return function_exists('mysqli_set_charset')
? @mysqli_set_charset($this->conn_id, $charset)
@@ -157,12 +159,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT version() AS ver";
+ return @mysqli_get_server_info($this->conn_id);
}
// --------------------------------------------------------------------
@@ -170,15 +171,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return resource
+ * @return mixed
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- $result = @mysqli_query($this->conn_id, $sql);
- return $result;
+ return @mysqli_query($this->conn_id, $this->_prep_query($sql));
}
// --------------------------------------------------------------------
@@ -188,20 +186,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
- // "DELETE FROM TABLE" returns 0 affected rows This hack modifies
- // the query so that it returns the number of affected rows
- if ($this->delete_hack === TRUE)
+ // 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))
{
- if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
- {
- $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
- }
+ return preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql);
}
return $sql;
@@ -212,18 +206,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -231,7 +219,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
$this->simple_query('SET AUTOCOMMIT=0');
$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
@@ -243,18 +231,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -269,18 +251,12 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -295,12 +271,11 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -312,7 +287,7 @@ class CI_DB_mysqli_driver extends CI_DB {
return $str;
}
- if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
+ if (function_exists('mysqli_real_escape_string') && is_object($this->conn_id))
{
$str = mysqli_real_escape_string($this->conn_id, $str);
}
@@ -328,7 +303,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
@@ -339,10 +314,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mysqli_affected_rows($this->conn_id);
}
@@ -352,10 +326,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @mysqli_insert_id($this->conn_id);
}
@@ -368,27 +341,25 @@ class CI_DB_mysqli_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -399,16 +370,16 @@ class CI_DB_mysqli_driver extends CI_DB {
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
+ $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char;
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
@@ -421,13 +392,12 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -437,13 +407,12 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "DESCRIBE ".$table;
+ return 'DESCRIBE '.$table;
}
// --------------------------------------------------------------------
@@ -451,10 +420,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return mysqli_error($this->conn_id);
}
@@ -464,10 +432,9 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return mysqli_errno($this->conn_id);
}
@@ -479,11 +446,10 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -494,24 +460,20 @@ class CI_DB_mysqli_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -522,11 +484,10 @@ class CI_DB_mysqli_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param string
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -543,15 +504,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -561,15 +521,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -580,17 +539,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
- return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
-
+
// --------------------------------------------------------------------
/**
@@ -598,7 +556,6 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -606,24 +563,17 @@ class CI_DB_mysqli_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -633,17 +583,14 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
-
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
@@ -657,25 +604,19 @@ class CI_DB_mysqli_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
$cases = '';
-
foreach ($final as $k => $v)
{
- $cases .= $k.' = CASE '."\n";
- foreach ($v as $row)
- {
- $cases .= $row."\n";
- }
-
- $cases .= 'ELSE '.$k.' END, ';
+ $cases .= $k.' = CASE '."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END, ';
}
- $sql .= substr($cases, 0, -2);
+ $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
- $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
@@ -687,13 +628,12 @@ class CI_DB_mysqli_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -703,31 +643,26 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
-
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -737,22 +672,15 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
-
- return $sql;
+ return $sql.' LIMIT '.$limit
+ .($offset > 0 ? ' OFFSET '.$offset : '');
}
// --------------------------------------------------------------------
@@ -760,18 +688,15 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
- * @param resource
+ * @param object
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mysqli_close($conn_id);
}
-
}
-
/* End of file mysqli_driver.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index cdd5399f2..7de036127 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Forge Class
*
@@ -39,13 +37,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Create database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _create_database($name)
+ public function _create_database($name)
{
- return "CREATE DATABASE ".$name;
+ return 'CREATE DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -53,13 +50,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
- * @return bool
+ * @return string
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
- return "DROP DATABASE ".$name;
+ return 'DROP DATABASE '.$name;
}
// --------------------------------------------------------------------
@@ -67,68 +63,35 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Process Fields
*
- * @access private
* @param mixed the fields
* @return string
*/
- function _process_fields($fields)
+ public function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
- }
-
- if (array_key_exists('TYPE', $attributes))
- {
- $sql .= ' '.$attributes['TYPE'];
- }
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '')
+ .( ! empty($attributes['TYPE']) ? ' '.$attributes['TYPE'] : '')
+ .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -146,15 +109,14 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -163,15 +125,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
if (count($primary_keys) > 0)
{
- $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
+ $key_name = $this->db->protect_identifiers(implode('_', $primary_keys));
+ $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -180,22 +139,20 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers($key);
$key = array($key_name);
}
- $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";
-
- return $sql;
+ return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
}
// --------------------------------------------------------------------
@@ -203,12 +160,11 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -219,31 +175,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
- {
- return $sql.$this->db->_protect_identifiers($fields);
- }
-
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
+ if ($alter_type === 'DROP')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.$this->db->protect_identifiers($fields);
}
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -253,18 +202,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file mysqli_forge.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 163788b6c..0a50cccac 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Result Class
*
@@ -41,10 +39,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
return @mysqli_num_rows($this->result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mysqli_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mysqli_fetch_field($this->result_id))
@@ -90,40 +85,36 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
while ($field = mysqli_fetch_object($this->result_id))
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
- $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
- $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
-
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = $type;
- $F->default = $field->Default;
- $F->max_length = $length;
- $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
+ $F = new stdClass();
+ $F->name = $field->Field;
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = $field->Default;
+ $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
+ $F->primary_key = (int) ($field->Key === 'PRI');
$retval[] = $F;
}
return $retval;
}
-
+
// --------------------------------------------------------------------
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_object($this->result_id))
{
@@ -141,10 +132,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return mysqli_data_seek($this->result_id, $n);
}
@@ -156,10 +146,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mysqli_fetch_assoc($this->result_id);
}
@@ -171,16 +160,14 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mysqli_fetch_object($this->result_id);
}
}
-
/* End of file mysqli_result.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_result.php */
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index ef7c89fab..3fdc5c723 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -18,15 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* MySQLi Utility Class
*
@@ -39,12 +37,11 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
/**
* List databases
*
- * @access private
- * @return bool
+ * @return string
*/
- function _list_databases()
+ public function _list_databases()
{
- return "SHOW DATABASES";
+ return 'SHOW DATABASES';
}
// --------------------------------------------------------------------
@@ -54,13 +51,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
- return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table);
+ return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -70,13 +66,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return string
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return "REPAIR TABLE ".$this->db->_escape_identifiers($table);
+ return 'REPAIR TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -84,11 +79,10 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
/**
* MySQLi Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -96,4 +90,4 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
}
/* End of file mysqli_utility.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 9c38dcbd6..c6621901b 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index bafab3d1b..b4a24cdca 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index f32559289..0f69fa9ef 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 28c374d99..d60f98bc4 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 0e9d46d3f..6ba39f0cd 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index e326a2801..e0ec687c8 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index b23a821d3..ba660856e 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 94666acbf..bae3fe853 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 457cf714a..de2b0abeb 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.1.0
@@ -46,9 +46,10 @@ class CI_DB_pdo_driver extends CI_DB {
// the character used to excape - not necessary for PDO
var $_escape_char = '';
+
+ // clause and character used for LIKE escape sequences
var $_like_escape_str;
var $_like_escape_chr;
-
/**
* The syntax to count rows is slightly different across different
@@ -57,29 +58,36 @@ class CI_DB_pdo_driver extends CI_DB {
*/
var $_count_string = "SELECT COUNT(*) AS ";
var $_random_keyword;
-
+
+ // need to track the pdo DSN, driver and options
+ var $dsn;
+ var $pdodriver;
var $options = array();
function __construct($params)
{
parent::__construct($params);
-
+
+ if (preg_match('/([^;]+):/', $this->dsn, $match) && count($match) == 2)
+ {
+ // If there is a minimum valid dsn string pattern found, we're done
+ // This is for general PDO users, who tend to have a full DSN string.
+ $this->pdodriver = end($match);
+ }
+ else
+ {
+ // Try to build a complete DSN string from params
+ $this->_connect_string($params);
+ }
+
// clause and character used for LIKE escape sequences
- if (strpos($this->hostname, 'mysql') !== FALSE)
+ // this one depends on the driver being used
+ if ($this->pdodriver == 'mysql')
{
$this->_like_escape_str = '';
$this->_like_escape_chr = '';
-
- //Prior to this version, the charset can't be set in the dsn
- if(is_php('5.3.6'))
- {
- $this->hostname .= ";charset={$this->char_set}";
- }
-
- //Set the charset with the connection options
- $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
}
- else if (strpos($this->hostname, 'odbc') !== FALSE)
+ elseif ($this->pdodriver == 'odbc')
{
$this->_like_escape_str = " {escape '%s'} ";
$this->_like_escape_chr = '!';
@@ -90,14 +98,94 @@ class CI_DB_pdo_driver extends CI_DB {
$this->_like_escape_chr = '!';
}
- if (strpos($this->hostname, 'sqlite') === FALSE)
+ $this->trans_enabled = FALSE;
+ $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+ }
+
+ /**
+ * Connection String
+ *
+ * @access private
+ * @param array
+ * @return void
+ */
+ function _connect_string($params)
+ {
+ if (strpos($this->hostname, ':'))
{
- $this->hostname .= ";dbname=".$this->database;
+ // hostname generally would have this prototype
+ // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);';
+ // We need to get the prefix (pdodriver used by PDO).
+ $dsnarray = explode(':', $this->hostname);
+ $this->pdodriver = $dsnarray[0];
+
+ // End dsn with a semicolon for extra backward compability
+ // if database property was not empty.
+ if ( ! empty($this->database))
+ {
+ $this->dsn .= rtrim($this->hostname, ';').';';
+ }
}
-
- $this->trans_enabled = FALSE;
+ else
+ {
+ // Invalid DSN, display an error
+ if ( ! array_key_exists('pdodriver', $params))
+ {
+ show_error('Invalid DB Connection String for PDO');
+ }
- $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+ // Assuming that the following DSN string format is used:
+ // $dsn = 'pdo://username:password@hostname:port/database?pdodriver=pgsql';
+ $this->dsn = $this->pdodriver.':';
+
+ // Add hostname to the DSN for databases that need it
+ if ( ! empty($this->hostname)
+ && strpos($this->hostname, ':') === FALSE
+ && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid')))
+ {
+ $this->dsn .= 'host='.$this->hostname.';';
+ }
+
+ // Add a port to the DSN for databases that can use it
+ if ( ! empty($this->port) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'ibm', 'cubrid')))
+ {
+ $this->dsn .= 'port='.$this->port.';';
+ }
+ }
+
+ // Add the database name to the DSN, if needed
+ if (stripos($this->dsn, 'dbname') === FALSE
+ && in_array($this->pdodriver, array('4D', 'pgsql', 'mysql', 'firebird', 'sybase', 'mssql', 'dblib', 'cubrid')))
+ {
+ $this->dsn .= 'dbname='.$this->database.';';
+ }
+ elseif (stripos($this->dsn, 'database') === FALSE && in_array($this->pdodriver, array('ibm', 'sqlsrv')))
+ {
+ if (stripos($this->dsn, 'dsn') === FALSE)
+ {
+ $this->dsn .= 'database='.$this->database.';';
+ }
+ }
+ elseif ($this->pdodriver === 'sqlite' && $this->dsn === 'sqlite:')
+ {
+ if ($this->database !== ':memory')
+ {
+ if ( ! file_exists($this->database))
+ {
+ show_error('Invalid DB Connection string for PDO SQLite');
+ }
+
+ $this->dsn .= (strpos($this->database, DIRECTORY_SEPARATOR) !== 0) ? DIRECTORY_SEPARATOR : '';
+ }
+
+ $this->dsn .= $this->database;
+ }
+
+ // Add charset to the DSN, if needed
+ if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci')))
+ {
+ $this->dsn .= 'charset='.$this->char_set.';';
+ }
}
/**
@@ -108,9 +196,9 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_connect()
{
- $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
-
- return new PDO($this->hostname, $this->username, $this->password, $this->options);
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+
+ return $this->pdo_connect();
}
// --------------------------------------------------------------------
@@ -123,10 +211,44 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_pconnect()
{
- $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
- $this->options['PDO::ATTR_PERSISTENT'] = TRUE;
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+ $this->options[PDO::ATTR_PERSISTENT] = TRUE;
- return new PDO($this->hostname, $this->username, $this->password, $this->options);
+ return $this->pdo_connect();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * PDO connection
+ *
+ * @access private called by the PDO driver class
+ * @return resource
+ */
+ function pdo_connect()
+ {
+ // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php
+ if ($this->pdodriver == 'mysql' && is_php('5.3.6'))
+ {
+ $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'";
+ }
+
+ // Connecting...
+ try
+ {
+ $db = new PDO($this->dsn, $this->username, $this->password, $this->options);
+ }
+ catch (PDOException $e)
+ {
+ if ($this->db_debug && empty($this->failover))
+ {
+ $this->display_error($e->getMessage(), '', TRUE);
+ }
+
+ return FALSE;
+ }
+
+ return $db;
}
// --------------------------------------------------------------------
@@ -146,6 +268,7 @@ class CI_DB_pdo_driver extends CI_DB {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
@@ -175,7 +298,6 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_set_charset($charset, $collation)
{
- // @todo - add support if needed
return TRUE;
}
@@ -204,6 +326,7 @@ class CI_DB_pdo_driver extends CI_DB {
function _execute($sql)
{
$sql = $this->_prep_query($sql);
+
$result_id = $this->conn_id->query($sql);
if (is_object($result_id))
@@ -231,6 +354,17 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _prep_query($sql)
{
+ if ($this->pdodriver === 'pgsql')
+ {
+ // Change the backtick(s) for Postgre
+ $sql = str_replace('`', '"', $sql);
+ }
+ elseif ($this->pdodriver === 'sqlite')
+ {
+ // Change the backtick(s) for SQLite
+ $sql = str_replace('`', '', $sql);
+ }
+
return $sql;
}
@@ -285,6 +419,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
$ret = $this->conn->commit();
+
return $ret;
}
@@ -310,6 +445,7 @@ class CI_DB_pdo_driver extends CI_DB {
}
$ret = $this->conn_id->rollBack();
+
return $ret;
}
@@ -348,7 +484,9 @@ class CI_DB_pdo_driver extends CI_DB {
if ($like === TRUE)
{
$str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
+ array($this->_like_escape_chr.'%',
+ $this->_like_escape_chr.'_',
+ $this->_like_escape_chr.$this->_like_escape_chr),
$str);
}
@@ -378,9 +516,9 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function insert_id($name=NULL)
{
- //Convenience method for postgres insertid
- if (strpos($this->hostname, 'pgsql') !== FALSE)
+ if ($this->pdodriver == 'pgsql')
{
+ //Convenience method for postgres insertid
$v = $this->_version();
$table = func_num_args() > 0 ? func_get_arg(0) : NULL;
@@ -389,8 +527,10 @@ class CI_DB_pdo_driver extends CI_DB {
{
$sql='SELECT LASTVAL() as ins_id';
}
+
$query = $this->query($sql);
- $row = $query->row();
+ $row = $query->row();
+
return $row->ins_id;
}
else
@@ -418,7 +558,9 @@ class CI_DB_pdo_driver extends CI_DB {
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $sql = $this->_count_string.$this->_protect_identifiers('numrows').' FROM ';
+ $sql .= $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ $query = $this->query($sql);
if ($query->num_rows() == 0)
{
@@ -427,6 +569,7 @@ class CI_DB_pdo_driver extends CI_DB {
$row = $query->row();
$this->_reset_select();
+
return (int) $row->numrows;
}
@@ -443,12 +586,19 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM `".$this->database."`";
+ if ($this->pdodriver == 'pgsql')
+ {
+ // Analog function to show all tables in postgre
+ $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'";
+ }
+ else
+ {
+ $sql = "SHOW TABLES FROM `".$this->database."`";
+ }
if ($prefix_limit !== FALSE AND $this->dbprefix != '')
{
- //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
- return FALSE; // not currently supported
+ return FALSE;
}
return $sql;
@@ -467,7 +617,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$table;
+ return 'SHOW COLUMNS FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
@@ -483,7 +633,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _field_data($table)
{
- return "SELECT TOP 1 FROM ".$table;
+ return 'SELECT TOP 1 FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
@@ -497,6 +647,7 @@ class CI_DB_pdo_driver extends CI_DB {
function _error_message()
{
$error_array = $this->conn_id->errorInfo();
+
return $error_array[2];
}
@@ -544,8 +695,8 @@ class CI_DB_pdo_driver extends CI_DB {
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
-
+ $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
+ $str .= $this->_escape_char;
}
else
{
@@ -575,7 +726,7 @@ class CI_DB_pdo_driver extends CI_DB {
$tables = array($tables);
}
- return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')';
+ return (count($tables) == 1) ? '`'.$tables[0].'`' : '('.implode(', ', $tables).')';
}
// --------------------------------------------------------------------
@@ -593,7 +744,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -611,7 +762,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -636,14 +787,11 @@ class CI_DB_pdo_driver extends CI_DB {
$valstr[] = $key." = ".$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
+ $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
+ $orderby = (count($orderby) >= 1) ? ' ORDER BY '.implode(', ', $orderby) : '';
+ $sql = 'UPDATE '.$this->_from_tables($table).' SET '.implode(', ', $valstr);
+ $sql .= ($where != '' && count($where) >= 1) ? ' WHERE '.implode(' ', $where) : '';
$sql .= $orderby.$limit;
return $sql;
@@ -664,8 +812,8 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _update_batch($table, $values, $index, $where = NULL)
{
- $ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
+ $ids = array();
+ $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : '';
foreach ($values as $key => $val)
{
@@ -680,12 +828,13 @@ class CI_DB_pdo_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
+ $sql = 'UPDATE '.$this->_from_tables($table).' SET ';
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
+
foreach ($v as $row)
{
$cases .= $row."\n";
@@ -695,7 +844,6 @@ class CI_DB_pdo_driver extends CI_DB {
}
$sql .= substr($cases, 0, -2);
-
$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
return $sql;
@@ -739,19 +887,20 @@ class CI_DB_pdo_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
+ $conditions = "\nWHERE ";
$conditions .= implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
$conditions .= " AND ";
}
+
$conditions .= implode("\n", $like);
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$this->_from_tables($table).$conditions.$limit;
}
// --------------------------------------------------------------------
@@ -769,27 +918,16 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _limit($sql, $limit, $offset)
{
- if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE)
+ if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite')
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
+ $offset = ($offset == 0) ? '' : $offset.', ';
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.'LIMIT '.$offset.$limit;
}
else
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
+ $sql .= 'LIMIT '.$limit;
+ $sql .= ($offset > 0) ? ' OFFSET '.$offset : '';
return $sql;
}
@@ -809,10 +947,7 @@ class CI_DB_pdo_driver extends CI_DB {
$this->conn_id = null;
}
-
}
-
-
/* End of file pdo_driver.php */
/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php
index bf3066529..478b2dbfb 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.1.0
@@ -96,7 +96,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= '`'.$this->db->_escape_identifiers($table).'` (';
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
@@ -111,6 +111,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
+ $numeric = array('SERIAL', 'INTEGER');
$sql .= "\n\t".$this->db->_protect_identifiers($field);
@@ -118,7 +119,11 @@ class CI_DB_pdo_forge extends CI_DB_forge {
if (array_key_exists('CONSTRAINT', $attributes))
{
- $sql .= '('.$attributes['CONSTRAINT'].')';
+ // Exception for Postgre numeric which not too happy with constraint within those type
+ if ( ! ($this->db->pdodriver == 'pgsql' && in_array($attributes['TYPE'], $numeric)))
+ {
+ $sql .= '('.$attributes['CONSTRAINT'].')';
+ }
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
@@ -219,7 +224,7 @@ class CI_DB_pdo_forge extends CI_DB_forge {
*/
function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE `'.$this->db->_protect_identifiers($table)."` $alter_type ".$this->db->_protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -271,7 +276,6 @@ class CI_DB_pdo_forge extends CI_DB_forge {
return $sql;
}
-
}
/* End of file pdo_forge.php */
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 559c2edb3..c333abc40 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.1.0
@@ -39,6 +39,16 @@
class CI_DB_pdo_result extends CI_DB_result {
/**
+ * @var bool Hold the flag whether a result handler already fetched before
+ */
+ protected $is_fetched = FALSE;
+
+ /**
+ * @var mixed Hold the fetched assoc array of a result handler
+ */
+ protected $result_assoc;
+
+ /**
* Number of rows in the result set
*
* @access public
@@ -46,7 +56,59 @@ class CI_DB_pdo_result extends CI_DB_result {
*/
function num_rows()
{
- return $this->result_id->rowCount();
+ if (empty($this->result_id) OR ! is_object($this->result_id))
+ {
+ // invalid result handler
+ return 0;
+ }
+ elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0)
+ {
+ // If rowCount return something, we're done.
+ return $num_rows;
+ }
+
+ // Fetch the result, instead perform another extra query
+ return ($this->is_fetched && is_array($this->result_assoc)) ? count($this->result_assoc) : count($this->result_assoc());
+ }
+
+ /**
+ * Fetch the result handler
+ *
+ * @access public
+ * @return mixed
+ */
+ function result_assoc()
+ {
+ // If the result already fetched before, use that one
+ if (count($this->result_array) > 0 OR $this->is_fetched)
+ {
+ return $this->result_array();
+ }
+
+ // Define the output
+ $output = array('assoc', 'object');
+
+ // Fetch the result
+ foreach ($output as $type)
+ {
+ // Define the method and handler
+ $res_method = '_fetch_'.$type;
+ $res_handler = 'result_'.$type;
+
+ $this->$res_handler = array();
+ $this->_data_seek(0);
+
+ while ($row = $this->$res_method())
+ {
+ $this->{$res_handler}[] = $row;
+ }
+ }
+
+ // Save this as buffer and marked the fetch flag
+ $this->result_array = $this->result_assoc;
+ $this->is_fetched = TRUE;
+
+ return $this->result_assoc;
}
// --------------------------------------------------------------------
@@ -78,6 +140,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
@@ -110,6 +173,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
return $this->db->display_error('db_unsuported_feature');
}
+
return FALSE;
}
}
@@ -178,6 +242,5 @@ class CI_DB_pdo_result extends CI_DB_result {
}
-
/* End of file pdo_result.php */
/* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php
index 90b46af3e..971ec8803 100644
--- a/system/database/drivers/pdo/pdo_utility.php
+++ b/system/database/drivers/pdo/pdo_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.1.0
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 50f096b5d..42329bded 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index f86ba2dda..756fd347a 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -63,32 +63,16 @@ class CI_DB_postgre_forge extends CI_DB_forge {
}
// --------------------------------------------------------------------
-
+
/**
- * Create Table
+ * Process Fields
*
- * @access private
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param mixed the fields
+ * @return string
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ function _process_fields($fields, $primary_keys=array())
{
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually
- if ($this->db->table_exists($table))
- {
- return TRUE;
- }
- }
-
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql = '';
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
@@ -184,6 +168,38 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql .= ',';
}
}
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create Table
+ *
+ * @access private
+ * @param string the table name
+ * @param array the fields
+ * @param mixed primary key(s)
+ * @param mixed key(s)
+ * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @return bool
+ */
+ function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ {
+ $sql = 'CREATE TABLE ';
+
+ if ($if_not_exists === TRUE)
+ {
+ // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually
+ if ($this->db->table_exists($table))
+ {
+ return TRUE;
+ }
+ }
+
+ $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= $this->_process_fields($fields, $primary_keys);
if (count($primary_keys) > 0)
{
@@ -249,40 +265,25 @@ class CI_DB_postgre_forge extends CI_DB_forge {
* @param string the field after which we should add the new field
* @return object
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
- {
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ function _alter_table($alter_type, $table, $fields, $after_field = '')
+ {
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
- // DROP has everything it needs now.
- if ($alter_type == 'DROP')
- {
- return $sql;
- }
+ // DROP has everything it needs now.
+ if ($alter_type == 'DROP')
+ {
+ return $sql.$this->db->_protect_identifiers($fields);
+ }
- $sql .= " $column_definition";
+ $sql .= $this->_process_fields($fields);
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
+ if ($after_field != '')
+ {
+ $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ }
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
-
- }
+ return $sql;
+ }
// --------------------------------------------------------------------
@@ -301,8 +302,6 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
return $sql;
}
-
-
}
/* End of file postgre_forge.php */
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 808e8bf72..9161bf955 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index f81f85782..dffd8c549 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index a6257cb1f..28c3caecd 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 96a5e0edb..2b723be0b 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 2bbd1dbc0..74c0dc549 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index c9914f28d..f00687e38 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 340cd3a66..9c50209ec 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -122,12 +122,23 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @param string database name
+ * @return bool
*/
- function db_select()
+ public function db_select($database = '')
{
- return $this->_execute('USE ' . $this->database);
+ if ($database === '')
+ {
+ $database = $this->database;
+ }
+
+ if ($this->_execute('USE '.$database))
+ {
+ $this->database = $database;
+ return TRUE;
+ }
+
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -608,4 +619,4 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index 4fa0596cd..2a7766927 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index 38aaec723..1ee19c2d1 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index f58b5bd04..e96df96f9 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0