[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]=>
[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]=>
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");
} 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';
--- /dev/null
+--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"