|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80827 SHOW WARNINGS fails when using native prepared statements
Submitted: 2021-03-03 23:13 UTC Modified: 2021-03-14 04:22 UTC
From: Assigned: john (profile)
Status: No Feedback Package: PDO MySQL
PHP Version: 7.4.3 OS: Ubuntu Focal
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-03-03 23:13 UTC]
There is a bug in the pdo_mysql driver with PDO::ATTR_EMULATE_PREPARES set to false that prevents a query such as `SHOW WARNINGS` from working properly.

I'm intending on writing a patch to fix this issue once I dig into it further, but I wanted to get the bug report live in case anyone else runs into this issue in the wild (e.g. Laravel disables emulated prepares for their DB implementation on top of PDO). 

Test script:

$db = new \PDO(...$params);
$db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$result = $db->query('SHOW WARNINGS')->fetchAll(); // causes a 2014 client error

$db = new \PDO(...$params);
$db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
$result = $db->query('SHOW WARNINGS')->fetchAll(); // works


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-03 23:14 UTC]
-Assigned To: +Assigned To: john
 [2021-03-03 23:17 UTC]
-PHP Version: 7.3.27 +PHP Version: 7.4.3
 [2021-03-05 08:35 UTC]
-Status: Assigned +Status: Feedback
 [2021-03-05 08:35 UTC]
I believe that already fixed this issue a while ago, you're just using a very old PHP 7.4 version.
 [2021-03-05 12:32 UTC]
I can't reproduce this with MariaDB but with MySQL I can confirm that Nikita's fix solves the problem.

However, I don't think I should be seeing any warnings. The results I get with MySQL are incorrect!

Nikita, are we sure that fallback to emulated prepares is the right solution here?
 [2021-03-05 15:30 UTC]
> Nikita, are we sure that fallback to emulated prepares is the right solution here?

I think it's the best we can do right now -- this works well for everything exception SHOW WARNINGS/ERRORS, which happen to make the failure of the initial prepare visible.

Ideally though, PDO::query() would not even try to use a prepared statement in the first place and directly execute the query (this is also good for efficiency).
 [2021-03-14 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 06:01:26 2024 UTC