Consider the following toy code:
<?php
$stmt = $my_sqli->prepare("UPDATE MyTable SET a=?, b=?, c=? WHERE x='whatever'");
if ($my_sqli->errno) {
throw new Exception(print_r($my_sqli->error_list, true)); // Condtion 1
} else if ($stmt === false) {
throw new Exception("There was an error ... good luck trying to find it!"); // Condition 2
}
When column c does not exist in MyTable, prepare() returns FALSE, as per the manual (Here: https://www.php.net/manual/en/mysqli.prepare.php).
I had hoped that when prepare failed, Condition 1
would trap the error and throw an informative exception, but it doesn't. Instead the error is trapped by Condition 2
because $my_sqli->errno
is 0.
How can I get a meaningful description of the error that occurred when $my_sqli->prepare
failed? I can't find anything in the manual (probably too obvious for me to spot it!)
See description above.