summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavey Shafik <davey@php.net>2020-10-27 09:47:56 +0000
committerGitHub <noreply@github.com>2020-10-27 09:47:56 +0000
commitc981209530f122d4e3033eebe66f160c0638ee91 (patch)
tree76f195e130469ab981529801bd56a1f9e5d66971
parent46b4241970c0a6438fc185ef900201c8cec74ed3 (diff)
downloadphp7-mysql-shim-c981209530f122d4e3033eebe66f160c0638ee91.zip
php7-mysql-shim-c981209530f122d4e3033eebe66f160c0638ee91.tar.gz
php7-mysql-shim-c981209530f122d4e3033eebe66f160c0638ee91.tar.bz2
mysql_fetch_field() returns a string for type
-rw-r--r--lib/mysql.php82
-rw-r--r--tests/MySqlShimTest.php24
2 files changed, 94 insertions, 12 deletions
diff --git a/lib/mysql.php b/lib/mysql.php
index d05d7a8..95f6e2b 100644
--- a/lib/mysql.php
+++ b/lib/mysql.php
@@ -428,7 +428,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 = 'varchar';
+ break;
+ case MYSQLI_TYPE_STRING:
+ $res->type = 'char';
+ break;
+ case MYSQLI_TYPE_GEOMETRY:
+ $res->type = 'geometry';
+ break;
+ case MYSQLI_TYPE_NEWDECIMAL:
+ $res->type = 'numeric';
+ break;
+ }
}
+
return $res;
}
diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php
index 02f4404..71c5c0a 100644
--- a/tests/MySqlShimTest.php
+++ b/tests/MySqlShimTest.php
@@ -979,62 +979,62 @@ class MySqlShimTest extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
0 => array(
'name' => 'id', 'max_length' => 1, 'not_null' => 1, 'primary_key' => 1,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 1, 'blob' => 0,
- 'type' => MYSQLI_TYPE_LONG, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'int', 'unsigned' => 0, 'zerofill' => 0
),
1 => array(
'name' => 'one', 'max_length' => 3, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 1, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
2 => array(
'name' => 'two', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 1, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
3 => array(
'name' => 'three', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 1, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
4 => array(
'name' => 'four', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 1, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
5 => array(
'name' => 'five', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
6 => array(
'name' => 'six', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
7 => array(
'name' => 'seven', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 1, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
8 => array(
'name' => 'eight', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_VAR_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'varchar', 'unsigned' => 0, 'zerofill' => 0
),
9 => array(
'name' => 'nine', 'max_length' => 3, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'char', 'unsigned' => 0, 'zerofill' => 0
),
10 => array(
'name' => 'ten', 'max_length' => 3, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 0,
- 'type' => MYSQLI_TYPE_STRING, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'char', 'unsigned' => 0, 'zerofill' => 0
),
11 => array(
'name' => 'eleven', 'max_length' => 1, 'not_null' => 0, 'primary_key' => 0,
'unique_key' => 0, 'multiple_key' => 0, 'numeric' => 0, 'blob' => 1,
- 'type' => MYSQLI_TYPE_BLOB, 'unsigned' => 0, 'zerofill' => 0
+ 'type' => 'blob', 'unsigned' => 0, 'zerofill' => 0
),
);