这是我的 getCategoryArrCon 函数脚本 connect_e-6ren">
gpt4 book ai didi

php - fatal error 说明 "Call to a member function bind_param() on a non-object"

转载 作者:行者123 更新时间:2023-11-29 02:57:47 24 4
gpt4 key购买 nike

我遇到了一个 fatal error ,我不知道哪里出了问题。

我的分类页面,

<?php 
require_once 'dbfunction.php';
require_once 'DBCategory.php';

$con=getDbConnect();
$categoryArr=getcategoryArrCon($con, STATUS_ACTIVE);

foreach ($categoryArr as $categoryName=>$CategoryInfoArr) {

?>

这是我的 getCategoryArrCon 函数脚本

<?php

define("STATUS_ACTIVE", 0);
define("STATUS_DELETE", 1);

function getcategoryArrCon($con, $status) {
$result = array();
if (!$con->connect_error) {
$sqlstr = "SELECT c.category, c.title, c.image" .
"FROM category c WHERE status=?";
$stmt = $con->prepare($sqlstr);
$stmt->bind_param("i", $status);
$stmt->excute();
$stmt->bind_result($category, $title, $image);
while ($stmt->fetch()) {
$result[$category] = [
"category" => $category,
"title" => $title,
"image" => $image
];
}
$stmt ->close();
}
return $result;
}
?>

最佳答案

如果您注意到,当您回显准备好的语句时,它看起来就像这样:

SELECT c.category, c.title, c.imageFROM category c WHERE status=?

c.imageFROM 中间的那个简单空格也很重要,可以使查询有效。

$sqlstr = "SELECT c.category, c.title, c.image" .
" FROM category c WHERE status=?";
// ^

或者为什么不把它做成一个衬垫:

$sqlstr = "SELECT c.category, c.title, c.image FROM category c WHERE status = ?";

还要确保 $stmt->excute(); 不是真正的拼写错误。它的->execute()

旁注:另外,利用->error检查准备是否正确。示例:

$stmt = $con->prepare($sqlstr) or die($con->error);

关于php - fatal error 说明 "Call to a member function bind_param() on a non-object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28643965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com