Hi Matthew,
1. PHP 8 has not introduced a change to PDO_MYSQL in respect of how values
are fetched. What makes the difference as to whether you get MySQL INT
values fetched as strings or integers is whether you are running PHP with
the mysqlnd https://dev.mysql.com/downloads/connector/php-mysqlnd/ and
emulation mode is off.

2. ZEROFILL in MySQL does not change how integers are stored, only how they
are displayed by MySQL clients. 00123 as a INT(5) ZEROFILL is still stored
as integer 123.

3. ZEROFILL is deprecated in MySQL 8. MySQL documentation advises "consider
using an alternative means of producing the effect of these attributes. For
example, applications can use the LPAD() function to zero-pad numbers up to
the desired width, or they can store the formatted numbers in CHAR columns."

4. Storing phone numbers and postal codes as integers is asking for
trouble, they are types of data which are fundamentally better represented
in storage as character types.

5. If you really need ints converted to string, turn
on PDO::ATTR_STRINGIFY_FETCHES.

Hope this helps.

Dave

On Sat, Feb 27, 2021 at 8:49 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
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

Reply via email to