php.net |  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: john@php.net 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] john@php.net
Description:
------------
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:
---------------
<?php

$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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-03 23:14 UTC] john@php.net
-Assigned To: +Assigned To: john
 [2021-03-03 23:17 UTC] john@php.net
-PHP Version: 7.3.27 +PHP Version: 7.4.3
 [2021-03-05 08:35 UTC] nikic@php.net
-Status: Assigned +Status: Feedback
 [2021-03-05 08:35 UTC] nikic@php.net
I believe that https://github.com/php/php-src/commit/f3d5877845358d011174cf87283b456cee6f7f53 already fixed this issue a while ago, you're just using a very old PHP 7.4 version.
 [2021-03-05 12:32 UTC] dharman@php.net
I can't reproduce this with MariaDB but with MySQL I can confirm that Nikita's fix solves the problem. 
https://phpize.online/?phpses=e1cac05bd0bc9086f6700ec82e7eaedb&sqlses=63c46b19554d6ac448aaeca4ef1a06e3&php_version=php8&sql_version=mysql80

However, I don't think I should be seeing any warnings. The results I get with MySQL are incorrect! 
https://phpize.online/?phpses=042e260408b41e85450cc702c2802aee&sqlses=63c46b19554d6ac448aaeca4ef1a06e3&php_version=php8&sql_version=mysql80

Nikita, are we sure that fallback to emulated prepares is the right solution here?
 [2021-03-05 15:30 UTC] nikic@php.net
> 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-2021 The PHP Group
All rights reserved.
Last updated: Wed Jul 28 11:01:24 2021 UTC