summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/mysqli/tests/003.phpt2
-rw-r--r--ext/mysqli/tests/020.phpt2
-rw-r--r--ext/mysqlnd/mysqlnd_ps_codec.c5
-rw-r--r--ext/mysqlnd/mysqlnd_wireprotocol.c3
-rw-r--r--ext/pdo_mysql/tests/bug80808.phpt27
5 files changed, 36 insertions, 3 deletions
diff --git a/ext/mysqli/tests/003.phpt b/ext/mysqli/tests/003.phpt
index 56a26602df..62f397587e 100644
--- a/ext/mysqli/tests/003.phpt
+++ b/ext/mysqli/tests/003.phpt
@@ -92,7 +92,7 @@ array(7) {
[2]=>
string(19) "2002-01-02 17:46:59"
[3]=>
- int(2010)
+ string(4) "2010"
[4]=>
string(19) "2010-07-10 00:00:00"
[5]=>
diff --git a/ext/mysqli/tests/020.phpt b/ext/mysqli/tests/020.phpt
index a2a8782f0f..d3bbd59332 100644
--- a/ext/mysqli/tests/020.phpt
+++ b/ext/mysqli/tests/020.phpt
@@ -87,7 +87,7 @@ array(7) {
[2]=>
%s(19) "2002-01-02 17:46:59"
[3]=>
- int(2010)
+ string(4) "2010"
[4]=>
%s(19) "2010-07-10 00:00:00"
[5]=>
diff --git a/ext/mysqlnd/mysqlnd_ps_codec.c b/ext/mysqlnd/mysqlnd_ps_codec.c
index e695d6ba79..eba4805b9d 100644
--- a/ext/mysqlnd/mysqlnd_ps_codec.c
+++ b/ext/mysqlnd/mysqlnd_ps_codec.c
@@ -74,6 +74,11 @@ ps_fetch_from_1_to_8_bytes(zval * zv, const MYSQLND_FIELD * const field, const u
case 1:uval = (uint64_t) uint1korr(*row);break;
}
+ if (field->flags & ZEROFILL_FLAG) {
+ DBG_INF("stringify due to zerofill");
+ tmp_len = sprintf((char *)&tmp, "%0*" PRIu64, (int) field->length, uval);
+ DBG_INF_FMT("value=%s", tmp);
+ } else
#if SIZEOF_ZEND_LONG==4
if (uval > INT_MAX) {
DBG_INF("stringify");
diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c
index 8cb94b6598..ed36c8404b 100644
--- a/ext/mysqlnd/mysqlnd_wireprotocol.c
+++ b/ext/mysqlnd/mysqlnd_wireprotocol.c
@@ -1600,7 +1600,8 @@ php_mysqlnd_rowp_read_text_protocol(MYSQLND_ROW_BUFFER * row_buffer, zval * fiel
} else if (Z_TYPE_P(current_field) == IS_STRING) {
/* nothing to do here, as we want a string and ps_fetch_from_1_to_8_bytes() has given us one */
}
- } else if (as_int_or_float && perm_bind.php_type == IS_LONG) {
+ } else if (as_int_or_float && perm_bind.php_type == IS_LONG
+ && !(fields_metadata[i].flags & ZEROFILL_FLAG)) {
zend_uchar save = *(p + len);
/* We have to make it ASCIIZ temporarily */
*(p + len) = '\0';
diff --git a/ext/pdo_mysql/tests/bug80808.phpt b/ext/pdo_mysql/tests/bug80808.phpt
new file mode 100644
index 0000000000..364b559a4c
--- /dev/null
+++ b/ext/pdo_mysql/tests/bug80808.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #80808: PDO returns ZEROFILL integers without leading zeros
+--SKIPIF--
+<?php
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+?>
+--FILE--
+<?php
+
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+$pdo = MySQLPDOTest::factory();
+
+$pdo->exec('DROP TABLE IF EXISTS test');
+$pdo->exec('CREATE TABLE test (postcode INT(4) UNSIGNED ZEROFILL)');
+$pdo->exec('INSERT INTO test (postcode) VALUES (\'0800\')');
+
+$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+var_dump($pdo->query('SELECT * FROM test')->fetchColumn(0));
+$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+var_dump($pdo->query('SELECT * FROM test')->fetchColumn(0));
+
+?>
+--EXPECT--
+string(4) "0800"
+string(4) "0800"