mysqli bind_param() 致命错误
我的代码有错误有人可以帮助我吗?
I Have an Error at my Code could someone help me?
<?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:xampphtdocsKarmintalender est.php 中的非对象上调用成员函数 bind_param()"
When I open it this error appears "Fatal error: Call to a member function bind_param() on a non-object in G:xampphtdocsKarmintalender est.php on line 8"
推荐答案
您在此行中的一个字段不存在,请检查它们.
One of your fields on this line doesn't exist,check them.
$sql = "SELECT name, kalender_ID FROM kalender WHERE ersteller_ID = ?";
此外,您应该检查 $stmt.
Also, you should be checking for $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;
}
}
相关文章