summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mysqli/mysqli_result.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2017-09-13 12:17:28 +0200
committerAndrey Andreev <narf@devilix.net>2017-09-13 12:17:28 +0200
commit9385cfed8e61c4568d5ec93c8ee8900f314a5a5a (patch)
tree0bdc724225634db408004d575cb52f90c4cc9a8a /system/database/drivers/mysqli/mysqli_result.php
parent146b131dab454885bf7ae943a93ecab53333520a (diff)
Fix #5260
Diffstat (limited to 'system/database/drivers/mysqli/mysqli_result.php')
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php58
1 files changed, 56 insertions, 2 deletions
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 929c2b455..0b3d9c2b4 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -112,9 +112,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
{
$retval[$i] = new stdClass();
$retval[$i]->name = $field_data[$i]->name;
- $retval[$i]->type = $field_data[$i]->type;
+ $retval[$i]->type = static::_get_field_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]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG);
$retval[$i]->default = $field_data[$i]->def;
}
@@ -124,6 +124,60 @@ class CI_DB_mysqli_result extends CI_DB_result {
// --------------------------------------------------------------------
/**
+ * Get field type
+ *
+ * Extracts field type info from the bitflags returned by
+ * mysqli_result::fetch_fields()
+ *
+ * @used-by CI_DB_mysqli_result::field_data()
+ * @param int $flags
+ * @return string
+ */
+ private static function _get_field_type($flags)
+ {
+ static $map;
+ isset($map) OR $map = array(
+ MYSQLI_TYPE_DECIMAL => 'decimal',
+ MYSQLI_TYPE_BIT => 'bit',
+ MYSQLI_TYPE_TINY => 'tinyint',
+ MYSQLI_TYPE_SHORT => 'smallint',
+ MYSQLI_TYPE_INT24 => 'mediumint',
+ MYSQLI_TYPE_LONG => 'int',
+ MYSQLI_TYPE_LONGLONG => 'bigint',
+ MYSQLI_TYPE_FLOAT => 'float',
+ MYSQLI_TYPE_DOUBLE => 'double',
+ MYSQLI_TYPE_TIMESTAMP => 'timestamp',
+ MYSQLI_TYPE_DATE => 'date',
+ MYSQLI_TYPE_TIME => 'time',
+ MYSQLI_TYPE_DATETIME => 'datetime',
+ MYSQLI_TYPE_YEAR => 'year',
+ MYSQLI_TYPE_NEWDATE => 'date',
+ MYSQLI_TYPE_INTERVAL => 'interval',
+ MYSQLI_TYPE_ENUM => 'enum',
+ MYSQLI_TYPE_SET => 'set',
+ MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
+ MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
+ MYSQLI_TYPE_BLOB => 'blob',
+ MYSQLI_TYPE_LONG_BLOB => 'longblob',
+ MYSQLI_TYPE_STRING => 'char',
+ MYSQLI_TYPE_VAR_STRING => 'varchar',
+ MYSQLI_TYPE_GEOMETRY => 'geometry'
+ );
+
+ foreach ($map as $flag => $name)
+ {
+ if ($flags & $flag)
+ {
+ return $name;
+ }
+ }
+
+ return $flags;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return void