summaryrefslogtreecommitdiffstats
path: root/lib/mysql.php
diff options
context:
space:
mode:
authorDavey Shafik <davey@php.net>2020-10-27 14:34:11 -0700
committerGitHub <noreply@github.com>2020-10-27 14:34:11 -0700
commitf99445512729d29eedac89b7375efc748793cdae (patch)
treeb10ae0df9059240dcf61824f21e86585e6bbd7a9 /lib/mysql.php
parent534f406552a2e5999c964c15b8524c958b193854 (diff)
parent187e5edf9a5eb1c4bcb4d65117a7ce5e2fa2b639 (diff)
downloadphp7-mysql-shim-f99445512729d29eedac89b7375efc748793cdae.zip
php7-mysql-shim-f99445512729d29eedac89b7375efc748793cdae.tar.gz
php7-mysql-shim-f99445512729d29eedac89b7375efc748793cdae.tar.bz2
Merge pull request #56 from dshafik/github-actions
Switch to GitHub Actions from Travis CI
Diffstat (limited to 'lib/mysql.php')
-rw-r--r--lib/mysql.php113
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;
}