面向对象的bind_pram未定义的函数

时间:2015-02-18 16:51:20

标签: php

如何解决这个问题?

  

致命错误:在C:\ Program中调用未定义的函数bind_param()   文件(x86)\ EasyPHP-DevServer-14.1VC11 \ data \ localweb \ functions.php on   第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);

1 个答案:

答案 0 :(得分:3)

你必须像这样调用bind_param:

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

此外,正如评论中所指出的那样,在处理数据库时在代码中添加错误检查以及更改列desc的名称是明智的,因为它是MySQL保留字。< / p>

重命名你的&#34; desc&#34;列到其他内容,或将其包装在刻度线中:

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