On Sat, Feb 27, 2021 at 9:50 AM Matty The Mad <ma...@themad.com.au> wrote:

> PHP 8.1 PDO has been changed so that when MySQL returns an integer it
> will no longer be returned as a string, but as an int.
>
> The problem is this breaks any sites that use UNSIGNED ZEROFILL integer
> fields in MySQL.
>
> I support a number of websites where the phone numbers and post codes
> are all UNSIGNED ZEROFILL.
>
> The post codes in MySQL are stored as 0800.
>
> In PHP 8.0 returned as string 0800
> In PHP 8.1 returned as integer 800
>
> 8.0.2
> string(10) "0742000000"
>
> 8.1.0-dev
> int(742000000)
>
> PDO shouldn't really be changing the data.
>
> I propose that:
> • any ZEROFILL integers are returned as string [or]
> • there's an option to control this when making the connection (I don't
> want to str_pad() at every place I've used ZEROFILL in the past) [or]
> • this backwards compatibility breaking change is removed until PHP 9.
>
> Matthew Asia
>

To clarify, what changed in PHP 8.1 is that emulated prepares now produce
the same results as native prepares. Or from a technical perspective, that
you get the same results independently of whether the text protocol or the
binary protocol is used to communicate with the MySQL server.

The handling of ZEROFILL does look like a bug to me. We should return
values with leading zeros as strings for both protocols. For reference,
this issue is tracked at https://bugs.php.net/bug.php?id=80808.

Regards,
Nikita

Reply via email to