php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80808 PDO returns ZEROFILL integers without leading zeros
Submitted: 2021-02-27 10:44 UTC Modified: 2021-03-01 15:57 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: matty at themad dot com dot au Assigned:
Status: Closed Package: PDO MySQL
PHP Version: Next Minor Version OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 7 = ?
Subscribe to this entry?

 
 [2021-02-27 10:44 UTC] matty at themad dot com dot au
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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-27 21:21 UTC] requinix@php.net
Discussion: https://externals.io/message/113294
 [2021-03-01 15:57 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2021-03-01 15:57 UTC] nikic@php.net
Same behavior for emulated and native prepares.
 [2021-03-02 09:59 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3a867b982755501b514d19418086972a0cc693e7
Log: Fixed bug #80808
 [2021-03-02 09:59 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC