Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Pdo\Mysql object is uninitialized" when opening a persistent connection #16314

Closed
Tracked by #6532
derrabus opened this issue Oct 9, 2024 · 5 comments · Fixed by #16369
Closed
Tracked by #6532

"Pdo\Mysql object is uninitialized" when opening a persistent connection #16314

derrabus opened this issue Oct 9, 2024 · 5 comments · Fixed by #16369

Comments

@derrabus
Copy link
Contributor

derrabus commented Oct 9, 2024

Description

The following code:

<?php

declare(strict_types=1);

$pdo = PDO::connect('mysql:host=127.0.0.1;dbname=test', 'root', '', [PDO::ATTR_PERSISTENT => true]);
$pdo->query('SELECT 1;');

Resulted in this output:

Fatal error: Uncaught Error: Pdo\Mysql object is uninitialized in /path/to/test.php on line 6

Error: Pdo\Mysql object is uninitialized in /path/to/test.php on line 6

Call Stack:
    0.0001     395016   1. {main}() /path/to/test.php:0
    0.0020     395152   2. PDO->query($query = 'SELECT 1;', $fetchMode = ???) /path/to/test.php:7

[1]    65142 bus error  php test.php

But I expected this output instead: No error.

The error is gone if I either set PDO::ATTR_PERSISTENT to false or call the oldschool constructor (new PDO(…)).

PHP Version

PHP 8.4-dev

Operating System

MacOS 15.0.1

@derrabus
Copy link
Contributor Author

derrabus commented Oct 9, 2024

This problem is not limited to MySQL. I can also reproduce it with a Postgres database:

$pdo = PDO::connect('pgsql:host=127.0.0.1;dbname=test', 'postgres', 'postgres', [PDO::ATTR_PERSISTENT => true]);
$pdo->query('SELECT 1;');

Output:

Fatal error: Uncaught Error: Pdo\Pgsql object is uninitialized

Again, if I set PDO::ATTR_PERSISTENT to false or connect via the old constructor, the problem is gone.

@derrabus
Copy link
Contributor Author

derrabus commented Oct 9, 2024

cc @Danack and @kocsismate since the new PDO classes are essentially your baby. Thank you very much for your work on that, by the way. ❤️

@kocsismate
Copy link
Member

@derrabus Thank you for the report (and the compliment as well)! I'll start to look into the problem tonight.

kocsismate added a commit to kocsismate/php-src that referenced this issue Oct 11, 2024
kocsismate added a commit to kocsismate/php-src that referenced this issue Oct 11, 2024
kocsismate added a commit to kocsismate/php-src that referenced this issue Oct 20, 2024
kocsismate added a commit to kocsismate/php-src that referenced this issue Oct 22, 2024
kocsismate added a commit to kocsismate/php-src that referenced this issue Oct 30, 2024
kocsismate added a commit that referenced this issue Nov 5, 2024
* PHP-8.4:
  Fix GH-16314 "Pdo\Mysql object is uninitialized" when opening a persistent connection (#16369)
@kocsismate
Copy link
Member

@derrabus Finally, I merged my changes so that it makes RC4. Thanks for your patience!

@derrabus
Copy link
Contributor Author

I'm reverting our workaround in doctrine/dbal#6623. Thank you very much for fixing the bug. 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants