一直在读书,我找不到准确的答案。我只想使用准备好的语句查询数据库,但我得到了:
调用未定义的方法mysqli :: execute()
这就是我目前的情况:
$conn=mysqli_connect($dbhost, $dbuser, $dbpass, $db) or die(mysqli_error($conn));
$conn->prepare("SELECT AccomodationID, PUPoint, PUTime, Entity_ID, Comments FROM ACCOMMODATION ORDER BY PUPoint ASC");
$conn->execute();
$conn->bind_result($AccomodationID, $PUPoint, $PUTime, $Entity_ID, $Comments);
$conn->store_result();
修改
解决。非常感谢TML的帮助。 mysqli-> prepare返回一个mysqli_stmt
对象。
$stmt = $conn->prepare("SELECT AccomodationID, PUPoint, PUTime, Entity_ID, Comments FROM ACCOMMODATION ORDER BY PUPoint ASC");
然后我可以使用该对象的方法,如下所示:
$stmt->execute();
$stmt->bind_result($AccomodationID, $PUPoint, $PUTime, $Entity_ID, $Comments);
$stmt->store_result();
答案 0 :(得分:3)
mysqli::prepare 返回一个mysqli_stmt
对象。 execute()是该对象上的方法,而不是原始mysqli
对象上的方法。
$conn=mysqli_connect($dbhost, $dbuser, $dbpass, $db) or die(mysqli_error($conn));
$conn->prepare("SELECT AccomodationID, PUPoint, PUTime, Entity_ID, Comments FROM ACCOMMODATION ORDER BY PUPoint ASC");
$stmt = $conn->execute();
$stmt->execute();
$stmt->bind_result($AccomodationID, $PUPoint, $PUTime, $Entity_ID, $Comments);
$stmt->store_result();