mysqli bind_param()致命错误

时间:2011-07-05 12:18:13

标签: php mysqli

我的代码有误,有人可以帮助我吗?

<?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()”

2 个答案:

答案 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