我正在尝试准备好的语句,但是下面的代码不起作用。我收到错误消息:
致命错误:在第12行的/var/www/prepared.php中的非对象上调用成员函数execute()
<?php
$mysqli = new mysqli("localhost", "root", "root", "test");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}
$stmt = $mysqli->prepare("INSERT INTO users (name, age) VALUES (?,?)");
// insert one row
$stmt->execute(array('one',1));
// insert another row with different values
$stmt->execute(array('two',1));
?>
另外,我需要对准备好的语句使用mysqli吗?谁能指出我关于从连接到插入再到带有错误处理的选择的准备好的语句的完整示例?