在这段代码中我得到错误:致命错误:调用未定义的方法mysqli_stmt :: fetch_array()
有什么问题?
$search= "player";
($sql = $db->prepare('select job from jobs where job like ?'));
$sql->bind_param('s', $search);
$sql->execute();
$sql->bind_result($search);
$data = array();
while ($sql->fetch_array(MYSQLI_ASSOC)) {
$data[] = array(
'label' => $row['job']
);
echo json_encode($data);
}
$sql -> close();
$db -> close();
感谢
答案 0 :(得分:10)
使用预准备语句没有fetch_array()
。使用mysqli_stmt::fetch()
代替或使用mysqli_stmt::fetchAll()
获取多条记录
检查手册:mysqli_stmt::fetch()或mysqli_stmt::fetchAll()