面向对象的bind_pram未定义函数


object oriented bind_pram undefined function

如何解决此问题?

致命错误:调用C:''Program中未定义的函数bind_param()上的Files(x86)''EasyHP-DevServer-14.1VC11''data''localweb''functions.php第15行

<?php
define('STATUS_ACTIVE', 0);
define('STATUS_DELETE', 1);
function getCategoryArrConn($conn, $status) {
$result = array();
if(!$conn->connect_error) {
    $sqlstr = "SELECT cat, title, img, desc " .
            "FROM category WHERE status=?";
    $stmt = $conn->prepare($sqlstr);
    $stmt = bind_param("i", $status);     //error in the line of code
    $stmt->execute();
    $stmt->bind_result($cat, $title, $img, $desc);
    while ($stmt->fetch()) {
        $result[$cat] = ["cat" => $cat,
                         "title" => $title,
                         "img" => $img,
                         "desc" => $desc];
    }
    $stmt->close();
}
return $result;
}
?>

它链接到函数所在的另一个PHP文件:

$categoryArr = getCategoryArrConn($conn, STATUS_ACTIVE);

您必须这样调用bind_param:

$stmt->bind_param('i', $status);

此外,正如注释所指出的,在处理DB时,明智的做法是在代码中添加错误检查,并更改列desc的名称,因为它是MySQL的保留字。

  • http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

要么将你的"desc"列重命名为其他列,要么用记号包起来:

$sqlstr = "SELECT cat, title, img, `desc` " .