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

From: Date: Sun, 14 Jan 2018 03:17:11 +0000
Subject: Bug #75813 [Opn]: 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-213534@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 User updated by: support at vid2chat dot com Reported by: support at vid2chat dot com Summary: Can't catch mysqli_sql_exception if bind_param() has mismatch Status: Open Type: Bug Package: MySQLi related Operating System: MacOS High Sierra PHP Version: 7.1.13 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#213534) next »