带有while循环的mysqli准备语句 [英] mysqli prepared statement with while loop
本文介绍了带有while循环的mysqli准备语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 mysqli 进行极其简单的查询.气死我了!
I am trying to do an extremely simple query using mysqli. It is driving me mad!
我只希望 $data
是来自 sql 查询的值的数组.
I just want $data
to be an array of the values from the sql query.
这是我的代码...
$req = $app->request();
$hashtag = $req->get('hashtag');
require_once 'Slim/lib/database.php';
$db = connect_db();
$statement = $db->prepare("SELECT `content` FROM `posts` WHERE `content` LIKE ?");
$newhashtag = '%#' . $hashtag . '%';
$statement -> bind_param("s", $newhashtag);
$statement -> execute();
$statement -> bind_result($result);
while ( $row = mysqli_fetch_array($statement) ) {
$data[] = $row;
}
print_r($data);
$statement -> close();
我刚刚收到一个错误 mysqli_fetch_array() 期望参数 1 为 mysqli_result,null given
并且使用 $result
或 $ 没有区别
fetch_array
I just get an error mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given
and it doesn't make a difference using $result
or $statement
on the fetch_array
推荐答案
替换这些行:
while ( $row = mysqli_fetch_array($statement) ) {
$data[] = $row;
}
这些:
while ($row = $statement->fetch()) {
$data[] = $row;
}
这篇关于带有while循环的mysqli准备语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文