diff options
author | Timothy Warren <tim@timshomepage.net> | 2012-03-02 15:29:27 +0100 |
---|---|---|
committer | Timothy Warren <tim@timshomepage.net> | 2012-03-02 15:29:27 +0100 |
commit | 6a3bda6a1fee45635f66f4e22d288f73334e9e48 (patch) | |
tree | 9a4a785e31daa46465e08a0b60ba7d076df04d6a /system/database/drivers/mysql | |
parent | 2d04624cb59d5852f8e61d610ab822252cad685a (diff) | |
parent | 06400c0397793132e7517a1e414d104800e16667 (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Diffstat (limited to 'system/database/drivers/mysql')
-rw-r--r-- | system/database/drivers/mysql/mysql_driver.php | 37 | ||||
-rw-r--r-- | system/database/drivers/mysql/mysql_result.php | 18 |
2 files changed, 27 insertions, 28 deletions
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 067710ff0..a7f08d1a8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -119,11 +119,23 @@ class CI_DB_mysql_driver extends CI_DB { /** * Select the database * + * @param string database name * @return bool */ - public function db_select() + public function db_select($database = '') { - return @mysql_select_db($this->database, $this->conn_id); + if ($database === '') + { + $database = $this->database; + } + + if (@mysql_select_db($database, $this->conn_id)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- @@ -405,25 +417,16 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - return mysql_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 mysql_errno($this->conn_id); + return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 8f04a936d..5a65d9c72 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -90,18 +90,14 @@ class CI_DB_mysql_result extends CI_DB_result { public function field_data() { $retval = array(); - while ($field = mysql_fetch_object($this->result_id)) + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { - preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - - $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; + $retval[$i] = new stdClass(); + $retval[$i]->name = mysql_field_name($this->result_id, $i); + $retval[$i]->type = mysql_field_type($this->result_id, $i); + $retval[$i]->max_length = mysql_field_len($this->result_id, $i); + $retval[$i]->primary_key = (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE) ? 0 : 1; + $retval[$i]->default = ''; } return $retval; |