Bug #80808 [NEW]: PDO returns ZEROFILL integers without leading zeros
| From: | matty at themad dot com dot au | Date: | Sat, 27 Feb 2021 10:44:38 +0000 |
| Subject: | Bug #80808 [NEW]: PDO returns ZEROFILL integers without leading zeros | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-232416@lists.php.net to get a copy of this message | ||
From: matty at themad dot com dot au
Operating system: Windows
PHP version: Next Minor Version
Package: PDO MySQL
Bug Type: Bug
Bug description:PDO returns ZEROFILL integers without leading zeros
Description:
------------
PDO originally returns integers and floats as a string. As of PHP 8.1 it
will return them as integers.
Note: A ZEROFILL integer is where an integer will be left padded with
0's until it reaches a certain length.
Since PHP doesn't support leading zero's in an integer they're removed.
8.0.2
string(10) "0742130050"
8.1.0-dev
int(742130050)
PDO should not lose data.
The solution I suggest is
Test script:
---------------
CREATE TABLE test (
postcode INT(4) UNSIGNED ZEROFILL NULL );
INSERT INTO test (postcode) VALUES ('0800');
SELECT * FROM test;
MariaDB [schools]> SELECT * FROM test;
+----------+
| postcode |
+----------+
| 0800 |
+----------+
1 row in set (0.000 sec)
$stmt = $pdo->prepare('SELECT * FROM test;');
$stmt->execute();
$result = $stmt->fetchObject();
var_dump($result->postcode);
Expected result:
----------------
string(4) "0800"
Actual result:
--------------
int(800)
--
Edit bug report at https://bugs.php.net/bug.php?id=80808&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80808&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80808&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80808&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80808&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80808&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80808&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80808&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80808&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80808&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80808&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80808&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80808&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80808&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80808&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80808&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80808&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80808&r=mysqlcfg