|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75964 mysqli::query emits php warning instead of throwing an exception
Submitted: 2018-02-15 14:09 UTC Modified: 2020-03-22 04:22 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: andre dot swinka at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: MySQLi related
PHP Version: 7.1.14 OS: CentOS release 6.9 (Final)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: andre dot swinka at gmail dot com
New email:
PHP Version: OS:


 [2018-02-15 14:09 UTC] andre dot swinka at gmail dot com
The PHP manual states, that errors, which occur using mysqli, can be converted into exceptions by using mysqli_report.

But even with corresponding settings made by using mysqli_report, \mysqli::query() is not throwing an exception but is emitting a PHP warning.

This makes it very hard to handle the issue locally as the emitted PHP warning is hitting the PHP error handler instead of a local try-catch block.

I am facing the issue with a mysql transaction deadlock/conflict right now, but it can be reproduced easily with an empty query, see test script and actual result.

mysqli should honor the settings made by using mysqli_report for all kinds of error.

Test script:

$mysqli = new \mysqli('<host>', '<user>', '<pwd>', '<database>'); // replace <host>,.. with connection settings

Expected result:
PHP Fatal error:  Uncaught mysqli_sql_exception: mysqli::query(): Empty query in /vagrant/test.php:5
Stack trace:
#0 /foo/test.php(5): mysqli->query('')
#1 {main}
  thrown in /foo/test.php on line 5

Actual result:
PHP Warning:  mysqli::query(): Empty query in /foo/test.php on line 5


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-09 18:16 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-03-09 18:16 UTC]
> mysqli should honor the settings made by using mysqli_report for
> all kinds of error.

There is a difference between mysqli and engine errors, though.
For instance, when an array is passed to mysqli_query(), the
engine raises a warning.  An empty string falls into the same
category of errors (although the warning is raised by mysqli).

So, this example doesn't qualify as bug.

There may be cases which shoud throw an exception instead of
raising a warning; can you please try to come up with some way to
reproduce those?
 [2020-03-22 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: Thu Jul 18 23:01:30 2024 UTC