Problem/Motivation

PHP 8.1 has fixed a bug in the PDO MySQL driver where if you use \PDO::ATTR_EMULATE_PREPARES then all fetches are string-ified. In PHP 8.1 integer db fields would return an integer value. However, all other core supported DBs are using the \PDO::ATTR_STRINGIFY_FETCHES option (to align with the behaviour of MySQL prior to PHP 8.1). See https://externals.io/message/113294 for further disucussion.

We could discuss changing this behaviour is future versions of Drupal. However this is likely to be a major version only change as it results in changing underlying data types and it extremely disruptive.

Steps to reproduce

See test runs in #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves) - fixed in commit https://git.drupalcode.org/project/drupal/-/merge_requests/937/diffs?com...

Proposed resolution

Add \PDO::ATTR_STRINGIFY_FETCHES to \Drupal\Core\Database\Driver\mysql\Connection::open()

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

CommentFileSizeAuthor
#2 3224245-2.patch860 bytesalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
860 bytes
mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Yes, this is the only possible fix for now I guess.

  • catch committed fd0b13a on 9.3.x
    Issue #3224245 by alexpott: Open MySQL connection using \PDO::...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed fd0b13a and pushed to 9.3.x. Thanks!

If we even want to remove this, it'll need to be after we require PHP 8.1, making it a 10.x+ change.

mondrake’s picture

Issue tags: +PHP 8.1
andypost’s picture

Sqlite and pgsql also affected because it's pdo change https://github.com/php/php-src/blob/php-8.1.0beta1/UPGRADING#L116

alexpott’s picture

@andypost see issue summary - we already set this option for the other drivers.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.