Bug #75813 [Opn->Csd]: Can't catch mysqli_sql_exception if bind_param() has mismatch

From: Date: Sat, 19 Sep 2020 22:49:36 +0000
Subject: Bug #75813 [Opn->Csd]: Can't catch mysqli_sql_exception if bind_param() has mismatch
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229084@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75813&edit=1 ID: 75813 Updated by: cmb@php.net Reported by: support at vid2chat dot com Summary: Can't catch mysqli_sql_exception if bind_param() has mismatch -Status: Open +Status: Closed Type: Bug Package: MySQLi related Operating System: MacOS High Sierra PHP Version: 7.1.13 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This has been fixed with commit 7a95e94[1] (i.e. as of PHP 8.0.0). [1] <http://git.php.net/?p=php-src.git;a=commit;h=7a95e943d642e05532979a06221c476183eac7e4> Previous Comments: ------------------------------------------------------------------------ [2018-01-14 03:17:09] support at vid2chat dot com Description: ------------ Using mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT) converts all MySQLi errors to exceptions, except for if there is a mismatch in bind_result(). This occurs in both the bound variables and types. An error with the following message is shown: Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Test script: --------------- mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $stmt = $mysqli->prepare("SELECT * FROM table WHERE name = ?"); $stmt->bind_param("si", $_POST['name'], $_POST['age']); $stmt->execute(); $arr = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); if(!$arr) exit('No rows'); var_export($arr); $stmt->close(); Expected result: ---------------- I should be able to catch all MySQLi exceptions, but this specific error is not converted to an exception. ------------------------------------------------------------------------ [2018-01-13 21:03:07] support at vid2chat dot com Description: ------------ Using mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT) converts all MySQLi errors to exceptions, except for if there is a mismatch in bind_result(). This occurs in both the bound variables and types. An error with the following message is shown: Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Test script: --------------- $stmt = $mysqli->prepare("SELECT id, name, age FROM myTable WHERE name = ?"); $stmt->bind_param("si", $_POST['name'], $_POST['age']); $stmt->execute(); $arr = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); if(!$arr) exit('No rows'); var_export($arr); $stmt->close(); Expected result: ---------------- I should be able to catch all MySQLi exceptions, but this specific error is not converted to an exception. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75813&edit=1

« previous php.bugs (#229084) next »