summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mysqli
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/mysqli')
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php17
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php2
2 files changed, 12 insertions, 7 deletions
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index ae17703ac..78a4bef0f 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -387,7 +387,7 @@ class CI_DB_mysqli_driver extends CI_DB {
* Returns an object with field data
*
* @param string $table
- * @return object
+ * @return array
*/
public function field_data($table = '')
{
@@ -396,19 +396,24 @@ 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));
+ if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
+ {
+ return 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];
+
+ sscanf($query[$i]->Type, '%[a-z](%d)',
+ $retval[$i]->type,
+ $retval[$i]->max_length
+ );
+
$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');
}
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 15e15cd5f..d55188e68 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -102,7 +102,7 @@ class CI_DB_mysqli_result extends CI_DB_result {
$retval[$i]->type = $field_data[$i]->type;
$retval[$i]->max_length = $field_data[$i]->max_length;
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
- $retval[$i]->default = '';
+ $retval[$i]->default = $field_data[$i]->def;
}
return $retval;