Skip to content

Fix PHP error handling muscling in on database error reports #18450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jabcreations opened this issue Apr 28, 2025 · 1 comment
Closed

Fix PHP error handling muscling in on database error reports #18450

jabcreations opened this issue Apr 28, 2025 · 1 comment

Comments

@jabcreations
Copy link

jabcreations commented Apr 28, 2025

Description

The following code:

<?php
$result = mysqli_query($db,$query);

if ($result) {}
else {mysqli_error_report($query,mysqli_error($db),__FUNCTION__);}

Resulted in this output:
[Database error] that is now handled by the PHP error handler.

But I expected this output instead:
Database errors should not be handled by PHP error handling!

This changed sometime in the past 1-3 years however I have been too overwhelmed to prioritize pursuing this issue until now.

No, I explicitly do not want to go through my platform and add the mess of ~1,500 instances of try / catch. I have gone through a lot of documentation though there always seems to be something placed in an odd place or not properly worded / missing key words while using Control + F to find relevant information in the documentation.

PHP Version

Local server:
PHP 8.3.6 (cli) (built: Apr 10 2024 14:54:14) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies

Operating System

Both local WAMP and live LAMP servers.

@jabcreations
Copy link
Author

jabcreations commented Apr 28, 2025

Thanks to some helpful people I was pointed to using the following which prevents PHP from handling SQL errors:

<?php
mysqli_report(MYSQLI_REPORT_OFF);
$result = mysqli_query($db,$query);

if ($result) {}
else
{
 //This now works correctly:
 mysqli_error_report($query,mysqli_error($db),__FUNCTION__);
}
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant