【发布时间】:2015-03-23 15:26:16
【问题描述】:
我正在尝试使用 mysqli 进行非常简单的查询。快把我逼疯了!
我只希望$data 是来自 sql 查询的值的数组。
这是我的代码...
$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() expects parameter 1 to be mysqli_result, null given,在fetch_array 上使用$result 或$statement 并没有什么不同
【问题讨论】:
-
当你已经拥有
$statement->bind_result($result)时为什么还要使用while循环