diff options
Diffstat (limited to 'lib/mysql.php')
-rw-r--r-- | lib/mysql.php | 113 |
1 files changed, 111 insertions, 2 deletions
diff --git a/lib/mysql.php b/lib/mysql.php index d05d7a8..7c79210 100644 --- a/lib/mysql.php +++ b/lib/mysql.php @@ -411,14 +411,41 @@ namespace { return mysqli_fetch_lengths($result); } - function mysql_fetch_field($result) /* : object|*/ + function mysql_fetch_field($result, $field_offset = null) /* : object|*/ { + static $fields = array(); + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd } - $res = mysqli_fetch_field($result); + + $result_hash = spl_object_hash($result); + if ($field_offset === null) { + $fields[$result_hash][] = true; + $res = mysqli_fetch_field($result); + } elseif ($field_offset > mysqli_num_fields($result)) { + trigger_error('mysql_fetch_field(): Bad field offset', E_USER_WARNING); + return false; + } else { + $i = 0; + if (isset($fields[$result_hash])) { + $i = count($fields[$result_hash]); + } + + while ($i <= $field_offset) { + $res = mysqli_fetch_field($result); + + if ($res === false) { + return false; + } + + $fields[$result_hash][$i] = true; + $i++; + } + } + if ($res instanceof \stdClass) { $res->not_null = ($res->flags & MYSQLI_NOT_NULL_FLAG) ? 1 : 0; $res->primary_key = ($res->flags & MYSQLI_PRI_KEY_FLAG ) ? 1 : 0; @@ -428,7 +455,89 @@ namespace { $res->blob = ($res->flags & MYSQLI_BLOB_FLAG ) ? 1 : 0; $res->unsigned = ($res->flags & MYSQLI_UNSIGNED_FLAG ) ? 1 : 0; $res->zerofill = ($res->flags & MYSQLI_ZEROFILL_FLAG ) ? 1 : 0; + + switch ($res->type) { + case MYSQLI_TYPE_CHAR: + $res->type = 'tinyint'; + break; + case MYSQLI_TYPE_SHORT: + $res->type = 'smallint'; + break; + case MYSQLI_TYPE_DECIMAL: + $res->type = 'decimal'; + break; + case MYSQLI_TYPE_LONG: + $res->type = 'int'; + break; + case MYSQLI_TYPE_FLOAT: + $res->type = 'float'; + break; + case MYSQLI_TYPE_DOUBLE: + $res->type = 'double'; + break; + case MYSQLI_TYPE_NULL: + $res->type = 'null'; + break; + case MYSQLI_TYPE_TIMESTAMP: + $res->type = 'timestamp'; + break; + case MYSQLI_TYPE_LONGLONG: + $res->type = 'bigint'; + break; + case MYSQLI_TYPE_INT24: + $res->type = 'mediumint'; + break; + case MYSQLI_TYPE_DATE: + $res->type = 'date'; + break; + case MYSQLI_TYPE_TIME: + $res->type = 'time'; + break; + case MYSQLI_TYPE_DATETIME: + $res->type = 'datetime'; + break; + case MYSQLI_TYPE_YEAR: + $res->type = 'year'; + break; + case MYSQLI_TYPE_NEWDATE: + $res->type = 'date'; + break; + case MYSQLI_TYPE_BIT: + $res->type = 'bit'; + break; + case MYSQLI_TYPE_ENUM: + $res->type = 'enum'; + break; + case MYSQLI_TYPE_SET: + $res->type = 'set'; + break; + case MYSQLI_TYPE_TINY_BLOB: + $res->type = 'tinyblob'; + break; + case MYSQLI_TYPE_MEDIUM_BLOB: + $res->type = 'mediumblob'; + break; + case MYSQLI_TYPE_LONG_BLOB: + $res->type = 'longblob'; + break; + case MYSQLI_TYPE_BLOB: + $res->type = 'blob'; + break; + case MYSQLI_TYPE_VAR_STRING: + $res->type = 'string'; + break; + case MYSQLI_TYPE_STRING: + $res->type = 'string'; + break; + case MYSQLI_TYPE_GEOMETRY: + $res->type = 'geometry'; + break; + case MYSQLI_TYPE_NEWDECIMAL: + $res->type = 'numeric'; + break; + } } + return $res; } |