From 7c251b38b690183b590adeb31d5155d043b6f74b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Dec 2011 16:37:23 +0200 Subject: Improve the Encryption library --- system/libraries/Encrypt.php | 92 +++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 92b0b3c4a..d9f40b0d5 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -1,13 +1,13 @@ -get_key($key); - - if ($this->_mcrypt_exists === TRUE) - { - $enc = $this->mcrypt_encode($string, $key); - } - else - { - $enc = $this->_xor_encode($string, $key); - } - - return base64_encode($enc); + $method = ($this->_mcrypt_exists === TRUE) ? 'mcrypt_encode' : '_xor_encode'; + return base64_encode($this->$method($string, $this->get_key($key))); } // -------------------------------------------------------------------- @@ -149,28 +139,13 @@ class CI_Encrypt { */ public function decode($string, $key = '') { - $key = $this->get_key($key); - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { return FALSE; } - $dec = base64_decode($string); - - if ($this->_mcrypt_exists === TRUE) - { - if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) - { - return FALSE; - } - } - else - { - $dec = $this->_xor_decode($dec, $key); - } - - return $dec; + $method = ($this->_mcrypt_exists === TRUE) ? 'mcrypt_decode' : '_xor_decode'; + return $this->$method(base64_decode($string), $this->get_key($key)); } // -------------------------------------------------------------------- @@ -197,6 +172,10 @@ class CI_Encrypt { log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.'); return FALSE; } + elseif (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) + { + return FALSE; + } // decode it first // set mode temporarily to what it was when string was encoded with the legacy @@ -205,12 +184,6 @@ class CI_Encrypt { $this->set_mode($legacy_mode); $key = $this->get_key($key); - - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) - { - return FALSE; - } - $dec = base64_decode($string); if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) @@ -242,17 +215,18 @@ class CI_Encrypt { protected function _xor_encode($string, $key) { $rand = ''; - while (strlen($rand) < 32) + do { $rand .= mt_rand(0, mt_getrandmax()); } + while (strlen($rand) < 32); $rand = $this->hash($rand); $enc = ''; - for ($i = 0; $i < strlen($string); $i++) + for ($i = 0, $ls = strlen($string), $lr = strlen($rand); $i < $ls; $i++) { - $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1)); + $enc .= $rand[($i % $lr)].($rand[($i % $lr)] ^ $string[$i]); } return $this->_xor_merge($enc, $key); @@ -275,9 +249,9 @@ class CI_Encrypt { $string = $this->_xor_merge($string, $key); $dec = ''; - for ($i = 0; $i < strlen($string); $i++) + for ($i = 0, $l = strlen($string); $i < $l; $i++) { - $dec .= (substr($string, $i++, 1) ^ substr($string, $i, 1)); + $dec .= ($string[$i++] ^ $string[$i]); } return $dec; @@ -298,9 +272,9 @@ class CI_Encrypt { { $hash = $this->hash($key); $str = ''; - for ($i = 0; $i < strlen($string); $i++) + for ($i = 0, $ls = strlen($string), $lh = strlen($hash); $i < $ls; $i++) { - $str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1); + $str .= $string[$i] ^ $hash[($i % $lh)]; } return $str; @@ -359,18 +333,17 @@ class CI_Encrypt { */ protected function _add_cipher_noise($data, $key) { - $keyhash = $this->hash($key); - $keylen = strlen($keyhash); + $key = $this->hash($key); $str = ''; - for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j) + for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j) { - if ($j >= $keylen) + if ($j >= $lk) { $j = 0; } - $str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256); + $str .= chr((ord($data[$i]) + ord($key[$j])) % 256); } return $str; @@ -389,22 +362,21 @@ class CI_Encrypt { */ protected function _remove_cipher_noise($data, $key) { - $keyhash = $this->hash($key); - $keylen = strlen($keyhash); + $key = $this->hash($key); $str = ''; - for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j) + for ($i = 0, $j = 0, $ld = strlen($data), $lk = strlen($key); $i < $ld; ++$i, ++$j) { - if ($j >= $keylen) + if ($j >= $lk) { $j = 0; } - $temp = ord($data[$i]) - ord($keyhash[$j]); + $temp = ord($data[$i]) - ord($key[$j]); if ($temp < 0) { - $temp = $temp + 256; + $temp += 256; } $str .= chr($temp); @@ -435,7 +407,7 @@ class CI_Encrypt { * @param constant * @return string */ - function set_mode($mode) + public function set_mode($mode) { $this->_mcrypt_mode = $mode; return $this; @@ -485,7 +457,7 @@ class CI_Encrypt { */ public function set_hash($type = 'sha1') { - $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type; + $this->_hash_type = ($type !== 'sha1' AND $type !== 'md5') ? 'sha1' : $type; } // -------------------------------------------------------------------- @@ -498,11 +470,11 @@ class CI_Encrypt { */ public function hash($str) { - return ($this->_hash_type == 'sha1') ? sha1($str) : md5($str); + return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str); } } // END CI_Encrypt class /* End of file Encrypt.php */ -/* Location: ./system/libraries/Encrypt.php */ \ No newline at end of file +/* Location: ./system/libraries/Encrypt.php */ -- cgit v1.2.3-24-g4f1b From cc6dbda62c1c04d4e247308f980e64d5d13c932d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 06:35:17 +0200 Subject: Some more misc. stuff --- system/libraries/Encrypt.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index d9f40b0d5..63e3bb55e 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -46,15 +46,10 @@ class CI_Encrypt { protected $_mcrypt_cipher; protected $_mcrypt_mode; - /** - * Constructor - * - * Simply determines whether the mcrypt library exists. - */ public function __construct() { $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; - log_message('debug', "Encrypt Class Initialized"); + log_message('debug', 'Encrypt Class Initialized'); } // -------------------------------------------------------------------- @@ -95,7 +90,7 @@ class CI_Encrypt { * Set the encryption key * * @param string - * @return void + * @return object */ public function set_key($key = '') { @@ -457,7 +452,7 @@ class CI_Encrypt { */ public function set_hash($type = 'sha1') { - $this->_hash_type = ($type !== 'sha1' AND $type !== 'md5') ? 'sha1' : $type; + $this->_hash_type = ($type !== 'sha1' && $type !== 'md5') ? 'sha1' : $type; } // -------------------------------------------------------------------- @@ -474,7 +469,5 @@ class CI_Encrypt { } } -// END CI_Encrypt class - /* End of file Encrypt.php */ /* Location: ./system/libraries/Encrypt.php */ -- cgit v1.2.3-24-g4f1b From d655a997f7b98da29ea932084e2fb50956188141 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 10 Jan 2012 22:31:29 +0200 Subject: Two returns --- system/libraries/Encrypt.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 63e3bb55e..8cb4b1b19 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -180,7 +180,6 @@ class CI_Encrypt { $key = $this->get_key($key); $dec = base64_decode($string); - if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) { return FALSE; @@ -419,7 +418,7 @@ class CI_Encrypt { { if ($this->_mcrypt_cipher == '') { - $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256; + return $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256; } return $this->_mcrypt_cipher; @@ -436,7 +435,7 @@ class CI_Encrypt { { if ($this->_mcrypt_mode == '') { - $this->_mcrypt_mode = MCRYPT_MODE_CBC; + return $this->_mcrypt_mode = MCRYPT_MODE_CBC; } return $this->_mcrypt_mode; -- cgit v1.2.3-24-g4f1b From 7bb95dff569f465ad8887404c2f9d5304a2ff5b3 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 16 Jan 2012 09:23:14 -0500 Subject: APC throws "apc_store() expects parameter 3 to be long, string given". Validates the TTL to an integer. --- system/libraries/Cache/drivers/Cache_apc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index 93993d07a..a3dd46978 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -68,6 +68,7 @@ class CI_Cache_apc extends CI_Driver { */ public function save($id, $data, $ttl = 60) { + $ttl = (int) $ttl; return apc_store($id, array($data, time(), $ttl), $ttl); } -- cgit v1.2.3-24-g4f1b From f4cb94ef0fdc81f6d9d908a4a2d2efda62add379 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 15:16:55 +0200 Subject: Some more cleaning --- system/libraries/Encrypt.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 8cb4b1b19..7c8720fd6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -9,7 +9,7 @@ * 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 + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Encryption Class * @@ -447,7 +445,7 @@ class CI_Encrypt { * Set the Hash type * * @param string - * @return string + * @return void */ public function set_hash($type = 'sha1') { -- cgit v1.2.3-24-g4f1b From 0e4d2b652ec4b0027b188a7aa84a9862b968f780 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 23 Jan 2012 18:19:20 -0600 Subject: Fix bug #195 Fixes bug #195 regarding non-existent user agent strings when using force_download() helper. --- system/helpers/download_helper.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 4a1a79cc3..aea948d81 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -88,26 +88,20 @@ if ( ! function_exists('force_download')) { $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } - + // Generate the server headers - if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) + header('Content-Type: "'.$mime.'"'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header('Expires: 0'); + header("Content-Transfer-Encoding: binary"); + header("Content-Length: ".strlen($data)); + header('Pragma: no-cache'); + + // Internet Explorer-specific headers. + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { - header('Content-Type: "'.$mime.'"'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); header('Pragma: public'); - header("Content-Length: ".strlen($data)); - } - else - { - header('Content-Type: "'.$mime.'"'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($data)); } exit($data); -- cgit v1.2.3-24-g4f1b From ed6531362e9eb98eeb477c63e3c365f79333e724 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:26:42 +0200 Subject: Revert a space in the license agreement :) --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 7c8720fd6..f6eea3b7e 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -9,7 +9,7 @@ * 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 + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From e943bc418b1a233fce98fa5ae80d0873e1e5245f Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 24 Jan 2012 10:37:06 -0500 Subject: Cleaned up a few things in PDO driver --- system/database/drivers/pdo/pdo_driver.php | 71 ++++++++++++++++-------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 457cf714a..3d5412600 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -43,6 +43,8 @@ class CI_DB_pdo_driver extends CI_DB { var $dbdriver = 'pdo'; + var $pdo_driver = ''; + var $dsn = ''; // the character used to excape - not necessary for PDO var $_escape_char = ''; @@ -64,39 +66,44 @@ class CI_DB_pdo_driver extends CI_DB { { parent::__construct($params); - // clause and character used for LIKE escape sequences - if (strpos($this->hostname, 'mysql') !== FALSE) - { - $this->_like_escape_str = ''; - $this->_like_escape_chr = ''; + $host = explode(":", $this->hostname); + $this->pdo_driver = $host[0]; + + $this->dsn = $this->hostname; + + switch($this->pdo_driver) + { + case "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->dsn .= ";charset={$this->char_set}"; + } + + //Set the charset with the connection options + $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}"; + break; - //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}"; - } + case "odbc": + $this->_like_escape_str = " {escape '%s'} "; + $this->_like_escape_chr = '!'; + break; - //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) - { - $this->_like_escape_str = " {escape '%s'} "; - $this->_like_escape_chr = '!'; - } - else - { - $this->_like_escape_str = " ESCAPE '%s' "; - $this->_like_escape_chr = '!'; - } - - if (strpos($this->hostname, 'sqlite') === FALSE) - { - $this->hostname .= ";dbname=".$this->database; + case "sqlite": + + break; + + default: + $this->_like_escape_str = " ESCAPE '%s' "; + $this->_like_escape_chr = '!'; + break; } + $this->dsn .= ";dbname=".$this->database; $this->trans_enabled = FALSE; - $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } @@ -110,7 +117,7 @@ class CI_DB_pdo_driver extends CI_DB { { $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; - return new PDO($this->hostname, $this->username, $this->password, $this->options); + return new PDO($this->dsn, $this->username, $this->password, $this->options); } // -------------------------------------------------------------------- @@ -126,7 +133,7 @@ class CI_DB_pdo_driver extends CI_DB { $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 new PDO($this->dsn, $this->username, $this->password, $this->options); } // -------------------------------------------------------------------- @@ -379,7 +386,7 @@ 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->pdo_driver === "pgsql") { $v = $this->_version(); @@ -769,7 +776,7 @@ 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->pdo_driver === "cubrid" || $this->pdo_driver === "sqlite") { if ($offset == 0) { -- cgit v1.2.3-24-g4f1b From de15a0b7377db0ef3b1d43508401be3c2927c0ff Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 24 Jan 2012 16:26:11 -0500 Subject: Revert "Cleaned up a few things in PDO driver" This reverts commit e943bc418b1a233fce98fa5ae80d0873e1e5245f. --- system/database/drivers/pdo/pdo_driver.php | 71 ++++++++++++++---------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 3d5412600..457cf714a 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -43,8 +43,6 @@ class CI_DB_pdo_driver extends CI_DB { var $dbdriver = 'pdo'; - var $pdo_driver = ''; - var $dsn = ''; // the character used to excape - not necessary for PDO var $_escape_char = ''; @@ -66,44 +64,39 @@ class CI_DB_pdo_driver extends CI_DB { { parent::__construct($params); - $host = explode(":", $this->hostname); - $this->pdo_driver = $host[0]; - - $this->dsn = $this->hostname; - - switch($this->pdo_driver) - { - case "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->dsn .= ";charset={$this->char_set}"; - } - - //Set the charset with the connection options - $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}"; - break; - - case "odbc": - $this->_like_escape_str = " {escape '%s'} "; - $this->_like_escape_chr = '!'; - break; + // clause and character used for LIKE escape sequences + if (strpos($this->hostname, 'mysql') !== FALSE) + { + $this->_like_escape_str = ''; + $this->_like_escape_chr = ''; - case "sqlite": - - break; + //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}"; + } - default: - $this->_like_escape_str = " ESCAPE '%s' "; - $this->_like_escape_chr = '!'; - break; + //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) + { + $this->_like_escape_str = " {escape '%s'} "; + $this->_like_escape_chr = '!'; + } + else + { + $this->_like_escape_str = " ESCAPE '%s' "; + $this->_like_escape_chr = '!'; + } + + if (strpos($this->hostname, 'sqlite') === FALSE) + { + $this->hostname .= ";dbname=".$this->database; } - $this->dsn .= ";dbname=".$this->database; $this->trans_enabled = FALSE; + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } @@ -117,7 +110,7 @@ class CI_DB_pdo_driver extends CI_DB { { $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; - return new PDO($this->dsn, $this->username, $this->password, $this->options); + return new PDO($this->hostname, $this->username, $this->password, $this->options); } // -------------------------------------------------------------------- @@ -133,7 +126,7 @@ class CI_DB_pdo_driver extends CI_DB { $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; $this->options['PDO::ATTR_PERSISTENT'] = TRUE; - return new PDO($this->dsn, $this->username, $this->password, $this->options); + return new PDO($this->hostname, $this->username, $this->password, $this->options); } // -------------------------------------------------------------------- @@ -386,7 +379,7 @@ class CI_DB_pdo_driver extends CI_DB { function insert_id($name=NULL) { //Convenience method for postgres insertid - if ($this->pdo_driver === "pgsql") + if (strpos($this->hostname, 'pgsql') !== FALSE) { $v = $this->_version(); @@ -776,7 +769,7 @@ class CI_DB_pdo_driver extends CI_DB { */ function _limit($sql, $limit, $offset) { - if ($this->pdo_driver === "cubrid" || $this->pdo_driver === "sqlite") + if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE) { if ($offset == 0) { -- cgit v1.2.3-24-g4f1b From 5aca23eaeb6d8c4e665dd2cd23fe8d733bb94875 Mon Sep 17 00:00:00 2001 From: CroNiX Date: Wed, 25 Jan 2012 14:26:46 -0800 Subject: Change hardcoded "application" directory to use the APPPATH constant as it would not work if you relocate /application or /system folders outside of web root. --- user_guide_src/source/tutorial/static_pages.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index c7f737951..708eaeb7b 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -97,7 +97,7 @@ page actually exists: public function view($page = 'home') { - if ( ! file_exists('application/views/pages/'.$page.'.php')) + if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); -- cgit v1.2.3-24-g4f1b From 624010f68be35000b8518be25375d8cb4078225f Mon Sep 17 00:00:00 2001 From: CroNiX Date: Wed, 25 Jan 2012 14:52:11 -0800 Subject: Added bit about having mod_rewrite enabled for removing index.php Added note about htaccess rules might not work for all server configurations --- user_guide_src/source/general/urls.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/general/urls.rst b/user_guide_src/source/general/urls.rst index 857078b1c..6b390b559 100644 --- a/user_guide_src/source/general/urls.rst +++ b/user_guide_src/source/general/urls.rst @@ -39,9 +39,10 @@ By default, the **index.php** file will be included in your URLs:: example.com/index.php/news/article/my_article -You can easily remove this file by using a .htaccess file with some -simple rules. Here is an example of such a file, using the "negative" -method in which everything is redirected except the specified items: +If your Apache server has mod_rewrite enabled, you can easily remove this +file by using a .htaccess file with some simple rules. Here is an example +of such a file, using the "negative" method in which everything is redirected +except the specified items: :: @@ -53,6 +54,8 @@ method in which everything is redirected except the specified items: In the above example, any HTTP request other than those for existing directories and existing files is treated as a request for your index.php file. +.. note:: Note: These specific rules might not work for all server configurations. + Adding a URL Suffix =================== -- cgit v1.2.3-24-g4f1b From 2caf289a893b8af69bbdce3f29d84d29e5433b58 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 00:12:03 +0200 Subject: Improve the MySQL database driver --- system/database/drivers/mysql/mysql_driver.php | 322 +++++++++--------------- system/database/drivers/mysql/mysql_forge.php | 131 ++++------ system/database/drivers/mysql/mysql_result.php | 57 ++--- system/database/drivers/mysql/mysql_utility.php | 70 ++---- 4 files changed, 205 insertions(+), 375 deletions(-) diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 0f69a0723..067710ff0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -1,13 +1,13 @@ -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,10 +119,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @return bool */ - function db_select() + public function db_select() { return @mysql_select_db($this->database, $this->conn_id); } @@ -140,12 +131,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 +147,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 +159,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 +174,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 +194,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 +207,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 +219,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 +239,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 +259,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 +275,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 +291,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 +302,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 +314,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 +329,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 +357,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 +379,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 +394,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 +407,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 +419,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 +433,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 +447,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 +471,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 +491,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 +509,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 +526,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 +544,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 +551,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 +577,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 +598,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 +620,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 +635,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 +665,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 +680,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 a41a7b446..d3107134e 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,13 +1,13 @@ -$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->_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) . ")"; + $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->_escape_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 dcb99cd60..8f04a936d 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,13 +1,13 @@ -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 703524165..0e7c18e16 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -1,13 +1,13 @@ -db->_escape_identifiers($table); + return 'OPTIMIZE TABLE '.$this->db->_escape_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->_escape_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->database.'`.`'.$table.'`'); // No result means the table name was invalid if ($query === FALSE) @@ -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 '.$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,11 +152,9 @@ 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.'`, '; @@ -170,8 +162,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // 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,13 +189,13 @@ 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 .= $newline.$newline; + return $output.$newline.$newline; } return $output; @@ -219,4 +203,4 @@ class CI_DB_mysql_utility extends CI_DB_utility { } /* 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 */ -- cgit v1.2.3-24-g4f1b From 82c83078a91acc3ce25572e28096b0b4bbe8d67c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 26 Jan 2012 19:02:05 -0500 Subject: Added try catch example in style guide --- user_guide_src/source/general/styleguide.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst index b3dc08871..d8bdd0531 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -441,6 +441,13 @@ same level as the control statement that "owns" them. // ... } } + + try { + // ... + } + catch() { + // ... + } **CORRECT**:: @@ -470,6 +477,15 @@ same level as the control statement that "owns" them. // ... } } + + try + { + // ... + } + catch() + { + // ... + } Bracket and Parenthetic Spacing =============================== -- cgit v1.2.3-24-g4f1b From 1ff49e05b8cb6a7d41a5ed36ff477b8d51b4ef12 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 11:30:41 +0200 Subject: Improve the MySQLi database driver --- system/database/DB_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 313 ++++++++-------------- system/database/drivers/mysqli/mysqli_forge.php | 137 +++------- system/database/drivers/mysqli/mysqli_result.php | 57 ++-- system/database/drivers/mysqli/mysqli_utility.php | 34 +-- 5 files changed, 189 insertions(+), 354 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 661b42ced..7445a5069 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -257,7 +257,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)) { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index aff62a37d..c6ffb4929 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -1,13 +1,13 @@ -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,13 @@ 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(); + 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 +98,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,10 +113,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @return bool */ - function db_select() + public function db_select() { return @mysqli_select_db($this->conn_id, $this->database); } @@ -140,12 +125,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 +141,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 +153,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 +168,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 +188,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 +201,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 +213,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 +233,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 +253,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 +269,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 +285,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 +296,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 +308,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 +323,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 +352,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 +374,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 +389,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 +402,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 +414,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 +428,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 +442,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 +466,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 +486,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 +503,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 +521,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 +538,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 +545,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 +565,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 +586,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); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; + $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : ''; - return $sql; + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) + .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') + .$index.' IN('.implode(',', $ids).')'; } // -------------------------------------------------------------------- @@ -687,13 +610,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 +625,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 +654,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 +670,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 590efa939..319c6fdac 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,13 +1,13 @@ -$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 89dd4ded8..0a50cccac 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -1,13 +1,13 @@ -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 76bd49e31..3fdc5c723 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -1,13 +1,13 @@ -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 */ -- cgit v1.2.3-24-g4f1b From 3a91cabf0cb346bbd4d44fe249f9f726101ba310 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 11:42:28 +0200 Subject: Update the changelog --- user_guide_src/source/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 48011f208..bc77b201b 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -47,6 +47,8 @@ Release Date: Not Released get_compiled_insert(), get_compiled_update(), get_compiled_delete(). - Taking care of LIKE condition when used with MySQL UPDATE statement. - Adding $escape parameter to the order_by function, this enables ordering by custom fields. + - MySQLi driver now uses mysqli_get_server_info() for server version checking. + - MySQLi driver now supports persistent connections. - Libraries -- cgit v1.2.3-24-g4f1b From f055fa98c7c7dbdd44ca485cde9efe112f713123 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 20:36:23 +0200 Subject: Add PHP version check in db_pconnect() --- system/database/drivers/mysqli/mysqli_driver.php | 6 ++++++ user_guide_src/source/changelog.rst | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index c6ffb4929..a79b2a4ad 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -85,6 +85,12 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_pconnect() { + // 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); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index bc77b201b..e27ff8877 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -48,7 +48,7 @@ Release Date: Not Released - Taking care of LIKE condition when used with MySQL UPDATE statement. - Adding $escape parameter to the order_by function, this enables ordering by custom fields. - MySQLi driver now uses mysqli_get_server_info() for server version checking. - - MySQLi driver now supports persistent connections. + - MySQLi driver now supports persistent connections when running on PHP >= 5.3. - Libraries -- cgit v1.2.3-24-g4f1b From a3c5cfca6b4a1ec183f3b3c9af88c7f686cf167e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 20:50:33 +0200 Subject: Switch _process_fields() from private to protected --- system/database/drivers/mysqli/mysqli_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 319c6fdac..7de036127 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -66,7 +66,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { * @param mixed the fields * @return string */ - private function _process_fields($fields) + public function _process_fields($fields) { $current_field_count = 0; $sql = ''; -- cgit v1.2.3-24-g4f1b