在此代码中,我得到以下错误:致命错误:调用未定义方法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();
谢谢
使用准备好的语句就没有了fetch_array()。使用mysqli_stmt::fetch()代替或获取多个记录,请使用mysqli_stmt::fetchAll() 以下手册:mysqli_stmt :: fetch()或mysqli_stmt :: fetchAll()
fetch_array()
mysqli_stmt::fetch()
mysqli_stmt::fetchAll()