我有这样的代码,故意使查询错误:delete_test.php。
<?php
.....
$id = 1;
$sql = "xSELECT * FROM tbl_1 WHERE 1 AND id =?"; // Adding and an x to make this error
$stmt = $mysqli->stmt_init();
if(!$stmt->prepare($sql)){ // Line 56
echo "There is something wrong #1";
exit();
}else{
$stmt->bind_param("i", $id);
if(!$stmt->execute()){
echo "There is something wrong #2";
exit();
}
.....
}
.....
?>
当我运行 delete_test.php 时出现此错误:
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'xSELECT * FROM tbl_1 WHERE 1 AND id =?' at line 1 in C:\xampp\htdocs\delete_test.php:56 Stack trace: #0 C:\xampp\htdocs\delete_test.php(56): mysqli_stmt->prepare('xSELECT * FROM ...') #1 {main} thrown in C:\xampp\htdocs\delete_test.php on line 56
而不是打印这个:
There is something wrong #1
为什么 php 忽略echo "There is something wrong #1";了该行的行错误?
以及如何echo "There is something wrong #1";在该行的行错误处打印?
呼啦一阵风