Bug #80808 [Opn->Ver]: PDO returns ZEROFILL integers without leading zeros

From: Date: Mon, 01 Mar 2021 15:57:37 +0000
Subject: Bug #80808 [Opn->Ver]: PDO returns ZEROFILL integers without leading zeros
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232455@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80808&edit=1 ID: 80808 Updated by: nikic@php.net Reported by: matty at themad dot com dot au Summary: PDO returns ZEROFILL integers without leading zeros -Status: Open +Status: Verified Type: Bug Package: PDO MySQL Operating System: Windows PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: Same behavior for emulated and native prepares. Previous Comments: ------------------------------------------------------------------------ [2021-02-27 21:21:30] requinix@php.net Discussion: https://externals.io/message/113294 ------------------------------------------------------------------------ [2021-02-27 10:44:38] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80808&edit=1

« previous php.bugs (#232455) next »