Bug #75964 [NEW]: mysqli::query emits php warning instead of throwing an exception
From: andre dot swinka at gmail dot com
Operating system: CentOS release 6.9 (Final)
PHP version: 7.1.14
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli::query emits php warning instead of throwing an exception
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 bug report at https://bugs.php.net/bug.php?id=75964&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75964&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75964&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75964&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75964&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75964&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75964&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75964&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75964&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75964&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75964&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75964&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75964&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75964&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75964&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75964&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75964&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75964&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75964&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75964&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75964&r=mysqlcfg
Thread (3 messages)
- andre dot swinka at gmail dot com