summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB.php15
-rw-r--r--system/database/DB_active_rec.php14
-rw-r--r--system/database/DB_driver.php12
-rw-r--r--system/database/DB_forge.php2
-rw-r--r--system/database/DB_result.php2
-rw-r--r--system/database/drivers/mssql/mssql_driver.php12
-rw-r--r--system/database/drivers/mysql/mysql_driver.php12
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php10
-rw-r--r--system/database/drivers/oci8/oci8_driver.php6
-rw-r--r--system/database/drivers/odbc/odbc_driver.php4
-rw-r--r--system/database/drivers/odbc/odbc_result.php4
-rw-r--r--system/database/drivers/postgre/postgre_driver.php14
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php4
13 files changed, 54 insertions, 57 deletions
diff --git a/system/database/DB.php b/system/database/DB.php
index 513e5aefd..8bf1ba8ba 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -27,17 +27,12 @@ function &DB($params = '', $active_record_override = NULL)
// Load the DB config file if a DSN string wasn't passed
if (is_string($params) AND strpos($params, '://') === FALSE)
{
-
- $file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT;
-
- if ( ! file_exists($file_path))
+ // Is the config file in the environment folder?
+ if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT))
{
- log_message('debug', 'Database config for '.ENVIRONMENT.' environment is not found. Trying global config.');
- $file_path = APPPATH.'config/database'.EXT;
-
- if ( ! file_exists($file_path))
+ if ( ! file_exists($file_path = APPPATH.'config/database'.EXT))
{
- continue;
+ show_error('The configuration file database'.EXT.' does not exist.');
}
}
@@ -88,7 +83,7 @@ function &DB($params = '', $active_record_override = NULL)
{
parse_str($dns['query'], $extra);
- foreach($extra as $key => $val)
+ foreach ($extra as $key => $val)
{
// booleans please
if (strtoupper($val) == "TRUE")
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index ce9d1c1af..db8471364 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -954,7 +954,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
else
{
- $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v);
+ $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
}
}
@@ -1020,11 +1020,11 @@ class CI_DB_active_record extends CI_DB_driver {
if ($query->num_rows() == 0)
{
- return '0';
+ return 0;
}
$row = $query->row();
- return $row->numrows;
+ return (int) $row->numrows;
}
// --------------------------------------------------------------------
@@ -1156,7 +1156,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_set[] = array();
return;
}
-
+
ksort($row); // puts $row in the same order as our keys
if ($escape === FALSE)
@@ -1167,7 +1167,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
$clean = array();
- foreach($row as $value)
+ foreach ($row as $value)
{
$clean[] = $this->escape($value);
}
@@ -1425,7 +1425,7 @@ class CI_DB_active_record extends CI_DB_driver {
$index_set = FALSE;
$clean = array();
- foreach($v as $k2 => $v2)
+ foreach ($v as $k2 => $v2)
{
if ($k2 == $index)
{
@@ -1569,7 +1569,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
elseif (is_array($table))
{
- foreach($table as $single_table)
+ foreach ($table as $single_table)
{
$this->delete($single_table, $where, $limit, FALSE);
}
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 2d8f592e3..e7a9de475 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -767,7 +767,7 @@ class CI_DB_driver {
if ($query->num_rows() > 0)
{
- foreach($query->result_array() as $row)
+ foreach ($query->result_array() as $row)
{
if (isset($row['TABLE_NAME']))
{
@@ -834,7 +834,7 @@ class CI_DB_driver {
$query = $this->query($sql);
$retval = array();
- foreach($query->result_array() as $row)
+ foreach ($query->result_array() as $row)
{
if (isset($row['COLUMN_NAME']))
{
@@ -904,7 +904,7 @@ class CI_DB_driver {
$fields = array();
$values = array();
- foreach($data as $key => $val)
+ foreach ($data as $key => $val)
{
$fields[] = $this->_escape_identifiers($key);
$values[] = $this->escape($val);
@@ -932,7 +932,7 @@ class CI_DB_driver {
}
$fields = array();
- foreach($data as $key => $val)
+ foreach ($data as $key => $val)
{
$fields[$this->_protect_identifiers($key)] = $this->escape($val);
}
@@ -1175,7 +1175,7 @@ class CI_DB_driver {
$trace = debug_backtrace();
- foreach($trace as $call)
+ foreach ($trace as $call)
{
if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
{
@@ -1248,7 +1248,7 @@ class CI_DB_driver {
{
$escaped_array = array();
- foreach($item as $k => $v)
+ foreach ($item as $k => $v)
{
$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v);
}
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 27f2c372d..a71fca78f 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -99,7 +99,7 @@ class CI_DB_forge {
{
if (is_array($key))
{
- foreach($key as $one)
+ foreach ($key as $one)
{
$this->add_key($one, $primary);
}
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index fb4268c21..76e1d6abb 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -78,7 +78,7 @@ class CI_DB_result {
while ($row = $this->_fetch_object())
{
$object = new $class_name();
- foreach($row as $key => $value)
+ foreach ($row as $key => $value)
{
$object->$key = $value;
}
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 5a69132cd..65397ed8f 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -253,7 +253,7 @@ class CI_DB_mssql_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -267,9 +267,11 @@ class CI_DB_mssql_driver extends CI_DB {
// escape LIKE condition wildcards
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),
- $str);
+ $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.'_'),
+ $str
+ );
}
return $str;
@@ -551,7 +553,7 @@ class CI_DB_mssql_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index c9fc1ecab..c4691ba0b 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -286,7 +286,7 @@ class CI_DB_mysql_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -590,9 +590,9 @@ class CI_DB_mysql_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
- $valstr[] = sprintf('`%s` = %s', $key, $val);
+ $valstr[] = $key . ' = ' . $val;
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
@@ -627,11 +627,11 @@ class CI_DB_mysql_driver extends CI_DB {
$ids = array();
$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$ids[] = $val[$index];
- foreach(array_keys($val) as $field)
+ foreach (array_keys($val) as $field)
{
if ($field != $index)
{
@@ -643,7 +643,7 @@ class CI_DB_mysql_driver extends CI_DB {
$sql = "UPDATE ".$table." SET ";
$cases = '';
- foreach($final as $k => $v)
+ foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 8942100d4..ccdabce1a 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -287,7 +287,7 @@ class CI_DB_mysqli_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -571,7 +571,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
@@ -607,11 +607,11 @@ class CI_DB_mysqli_driver extends CI_DB {
$ids = array();
$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$ids[] = $val[$index];
- foreach(array_keys($val) as $field)
+ foreach (array_keys($val) as $field)
{
if ($field != $index)
{
@@ -623,7 +623,7 @@ class CI_DB_mysqli_driver extends CI_DB {
$sql = "UPDATE ".$table." SET ";
$cases = '';
- foreach($final as $k => $v)
+ foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 64f53cc3f..14df104ff 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -253,7 +253,7 @@ class CI_DB_oci8_driver extends CI_DB {
$sql = "begin $package.$procedure(";
$have_cursor = FALSE;
- foreach($params as $param)
+ foreach ($params as $param)
{
$sql .= $param['name'] . ",";
@@ -395,7 +395,7 @@ class CI_DB_oci8_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -655,7 +655,7 @@ class CI_DB_oci8_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index c8e03c356..81e0d7cf2 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -264,7 +264,7 @@ class CI_DB_odbc_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -523,7 +523,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index a81a2b8b7..5d64a464f 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -188,7 +188,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
function _odbc_fetch_object(& $odbc_result) {
$rs = array();
- $rs_obj = false;
+ $rs_obj = FALSE;
if (odbc_fetch_into($odbc_result, $rs)) {
foreach ($rs as $k=>$v) {
$field_name= odbc_field_name($odbc_result, $k+1);
@@ -210,7 +210,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
function _odbc_fetch_array(& $odbc_result) {
$rs = array();
- $rs_assoc = false;
+ $rs_assoc = FALSE;
if (odbc_fetch_into($odbc_result, $rs)) {
$rs_assoc=array();
foreach ($rs as $k=>$v) {
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 0bb7974d8..47ff36246 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -283,7 +283,7 @@ class CI_DB_postgre_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -330,21 +330,21 @@ class CI_DB_postgre_driver extends CI_DB {
$v = $this->_version();
$v = $v['server'];
- $table = func_num_args() > 0 ? func_get_arg(0) : null;
- $column = func_num_args() > 1 ? func_get_arg(1) : null;
+ $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
+ $column = func_num_args() > 1 ? func_get_arg(1) : NULL;
- if ($table == null && $v >= '8.1')
+ if ($table == NULL && $v >= '8.1')
{
$sql='SELECT LASTVAL() as ins_id';
}
- elseif ($table != null && $column != null && $v >= '8.0')
+ elseif ($table != NULL && $column != NULL && $v >= '8.0')
{
$sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
$query = $this->query($sql);
$row = $query->row();
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
}
- elseif ($table != null)
+ elseif ($table != NULL)
{
// seq_name passed in table parameter
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
@@ -568,7 +568,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 5bfc1f558..eb4e585b3 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -280,7 +280,7 @@ class CI_DB_sqlite_driver extends CI_DB {
{
if (is_array($str))
{
- foreach($str as $key => $val)
+ foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
@@ -537,7 +537,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}