Bug #75964 [Opn->Fbk]: mysqli::query emits php warning instead of throwing an exception
| From: | cmb@php.net | Date: | Mon, 09 Mar 2020 18:16:47 +0000 |
| Subject: | Bug #75964 [Opn->Fbk]: mysqli::query emits php warning instead of throwing an exception | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225986@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75964&edit=1
ID: 75964
Updated by: cmb@php.net
Reported by: andre dot swinka at gmail dot com
Summary: mysqli::query emits php warning instead of throwing
an exception
-Status: Open
+Status: Feedback
Type: Bug
Package: MySQLi related
Operating System: CentOS release 6.9 (Final)
PHP Version: 7.1.14
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> 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?
Previous Comments:
------------------------------------------------------------------------
[2018-02-15 14:09:33] andre dot swinka at gmail dot com
Description:
------------
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:
---------------
<?php
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$mysqli = new \mysqli('<host>', '<user>', '<pwd>',
'<database>'); // replace <host>,.. with connection settings
$mysqli->query('');
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75964&edit=1