mysqli bind_param() 致命错误

时间:2023-03-06
本文介绍了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;
     }
 }

这篇关于mysqli bind_param() 致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:简化:mysqli num_rows 不工作 下一篇:mySqli 绑定参数 LIKE 与通配符

相关文章