diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-03-05 13:23:57 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-03-05 13:23:57 +0100 |
commit | 74496c268ae7199082cad86e0fea65687d78a2c9 (patch) | |
tree | 7a02e9961dda1e6949c4cbd986c894ffb9ed15a3 /system/database/drivers/mysqli/mysqli_driver.php | |
parent | bb5dae46256cdcb0bcd204b6fa2fc628da6afb88 (diff) | |
parent | cc5af53346397846f2035dc2bf6a2c2f9b0cd4ab (diff) |
Merge upstream branch
Diffstat (limited to 'system/database/drivers/mysqli/mysqli_driver.php')
-rw-r--r-- | system/database/drivers/mysqli/mysqli_driver.php | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index dbba12e15..25b6ceca1 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); } // -------------------------------------------------------------------- @@ -403,40 +405,50 @@ 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(); - /** - * The error message string - * - * @return string - */ - protected function _error_message() - { - return mysqli_error($this->conn_id); + $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; } // -------------------------------------------------------------------- /** - * The error message number + * Error * - * @return int + * Returns an array containing code and message of the last + * database error that has occured. + * + * @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)); } // -------------------------------------------------------------------- |