我的代码有误,有人可以帮助我吗?
<?php
$db = new mysqli("localhost","root","","karmintalender");
$owner_ID = 1;
$sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $owner_ID);
$stmt->execute();
$stmt->bind_results($name, $kalender_ID);
while ($stmt->fetch()) {
echo $name . " " . $kalender_ID;
}
?>
当我打开它时,出现此错误“致命错误:在第8行的G:\ xampp \ htdocs \ Karmintalender \ test.php中的非对象上调用成员函数bind_param()”
答案 0 :(得分:3)
此行上的某个字段不存在,请检查它们。
$sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?";
此外,您应该检查$ stmt。
$db = new mysqli("localhost","root","","karmintalender");
$owner_ID = 1;
$sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?";
$stmt = $db->prepare($sql);
if($stmt){
$stmt->bind_param("i", $owner_ID);
$stmt->execute();
$stmt->bind_results($name, $kalender_ID);
while ($stmt->fetch()) {
echo $name . " " . $kalender_ID;
}
}
答案 1 :(得分:2)
应该是$ stmt-&gt; bind_result($ name,$ kalender_ID);
放弃s