mysqli_stmt_bind_param Fatal error with MYSQLI_REPORT_OFF set
Description
The following code:
<?php
mysqli_report(MYSQLI_REPORT_OFF);
$mysqli_report = mysqli_init();
mysqli_real_connect($mysqli_report, "localhost", "example", "example", "example");
try {
$sql = "SELECT * FROM `example` WHERE cvalue = ? OR cvalue = ?";
$stmt = $mysqli_report->prepare($sql);
if ($stmt === false) {
$error_msg = "unable to prepair: " . $mysqli_report->error;
die($error_msg);
}
$bind_text = "ii";
$bind_args = [13];
$result = mysqli_stmt_bind_param($stmt, $bind_text, ...$bind_args);
die("This should not run: ".json_encode($result));
} catch (Exception $e) {
error_log("in error log: " . $e->getMessage());
}
Resulted in this output:
PHP Fatal error: Uncaught ArgumentCountError: The number of elements in the type definition string must match the number of bind variables in mysqli.php:16
Stack trace:
#0 mysqli.php(16): mysqli_stmt_bind_param(Object(mysqli_stmt), 'ii', 13)
#1 {main}
thrown in mysqli.php on line 16
Fatal error: Uncaught ArgumentCountError: The number of elements in the type definition string must match the number of bind variables in mysqli.php:16
Stack trace:
#0 mysqli.php(16): mysqli_stmt_bind_param(Object(mysqli_stmt), 'ii', 13)
#1 {main}
thrown in mysqli.php on line 16
But I expected this output instead:
in error log: The number of elements in the type definition string must match the number of bind variables
PHP Version
PHP 8.1.4 (cli) (built: Mar 16 2022 09:33:31)
Operating System
Windows 11
ArgumentCountError is a type of Error, not a type of Exception (uppercase 'E').
If you want to catch any type of exception (lowercase 'e') then look for a Throwable.
Yep my bad still weird thou I expected the fatal error to be suppressed. $result to be false. and the error given over: $stmt->error_list
mysqli_report() affects things that happen with MySQL and the database, like invalid queries or connection problems. The ArgumentCountError isn't one of those: it's about you calling the function with the wrong number of arguments. The same thing happens calling just about any other PHP function incorrectly too.