根据 php 手册,您可以通过询问 $stmt->error 和 $stmt->errno 来检索任何准备好的语句方法中的错误,但是 bind_param 方法似乎永远不会将这些设置为错误,其他人可以确认吗?或者告诉我我错过了什么?
例如:
echo "Start\n";
$db = new mysqli('localhost','test','xxxxxx','test');
$val = 1;
$st = $db->prepare('insert into tblTest set field1=?');
if($st == false)
{
printf("prepare: %s %d\n",$db->error,$st->errno);
}
$rs = $st->bind_param('is', $val);
if($rs == false)
{
printf("bind_param: %s %d\n",$st->error,$st->errno);
}
$rs = $st->execute();
if($rs == false)
{
printf("execute: %s %d\n",$st->error,$st->errno);
}
$rs = $st->close();
if($rs == false)
{
printf("close: %s %d\n",$st->error,$st->errno);
}
echo "Finish\n";
从命令行运行上述显示:
Start
PHP Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in test.php on line 14
bind_param: 0
execute: No data supplied for parameters in prepared statement 2031
Finish
所以 php 将其视为警告,bind_param 返回 false,但未设置错误和 errno。执行也失败并正确设置了错误和错误号
这是一个错误吗?