From 4be5de1d11eefd9f0b7cf0589a2942f067cefe35 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 15:45:41 +0200 Subject: Replaced DB methods _error_message() and _error_number() with error() (issue #1097) --- system/database/drivers/mysqli/mysqli_driver.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'system/database/drivers/mysqli/mysqli_driver.php') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index dbba12e15..031371345 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -418,25 +418,16 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @return int + * @return array */ - protected function _error_number() + public function error() { - return mysqli_errno($this->conn_id); + return array('code' => mysqli_errno($this->conn_id), 'message' => mysqli_error($this->conn_id)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 08856b8738ea4fc17b13986c9f2619383cb4a6e9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 03:19:28 +0200 Subject: Improve DB version() implementation and add pg_version() support --- system/database/drivers/mysqli/mysqli_driver.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/mysqli/mysqli_driver.php') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 031371345..19353944d 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -157,13 +157,15 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * * @return string */ - protected function _version() + public function version() { - return @mysqli_get_server_info($this->conn_id); + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = @mysqli_get_server_info($this->conn_id); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3722e50439fd88281f8730fd329b41812cd19963 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 15:04:38 +0200 Subject: Fix MySQL/MySQLi field_data() --- system/database/drivers/mysqli/mysqli_driver.php | 31 +++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'system/database/drivers/mysqli/mysqli_driver.php') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 19353944d..25b6ceca1 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -405,16 +405,35 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Returns an object with field data * * @param string the table name - * @return string + * @return object */ - protected function _field_data($table) + public function field_data($table = '') { - return 'DESCRIBE '.$table; + if ($table == '') + { + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; + } + + $query = $this->query('DESCRIBE '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1]; + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]); + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 032e7ea646b953a8f4d28327d7f487de2ffa7288 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Mar 2012 19:48:35 +0200 Subject: Resolve _protect_identifiers()/protect_identifiers() usage issues --- system/database/drivers/mysqli/mysqli_driver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/mysqli/mysqli_driver.php') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 25b6ceca1..d06119a13 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -353,7 +353,7 @@ class CI_DB_mysqli_driver extends CI_DB { 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; @@ -399,7 +399,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ 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); } // -------------------------------------------------------------------- @@ -417,7 +417,7 @@ class CI_DB_mysqli_driver extends CI_DB { return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; } - $query = $this->query('DESCRIBE '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query = $this->query('DESCRIBE '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); $query = $query->result_object(); $retval = array(); -- cgit v1.2.3-24-g4f1b