>我正在尝试调用插入新记录并返回最后一个 id 的存储过程。当我调用该页面时,我收到上述错误,并引用第 6 行。
$Str = 'Hello world';
$parentId = 1;
$lastId = 0;
$statement = $con->prepare('call createRecordReturnsId( ? , ? )');
$statement->bind_param("si",$Str,$parentId);
$statement->bind_result($lastId);
$statement->execute();
我只需要将绑定语句(第 7 行)移动到执行语句(第 8 行)
之后
以下顺序有效:
$Str = 'Hello world';
$parentId = 1;
$lastId = 0;
$statement = $con->prepare('call createRecordReturnsId( ? , ? )');
$statement->bind_param("si",$Str,$parentId);
$statement->execute();
$statement->bind_result($lastId);
正确的操作顺序很重要,因为在调用存储过程时,mysqli 不知道在执行语句之前将返回的变量数。