[英]Return mysqli result as array
如何将mysqli查询的结果作为关联数组返回?
我想将其作为数组传递到我的视图层,以便可以将html与模型层分开。 这是一张桌子,所以它可以有无限的行...
if ($statement = $this->mysqli->db->prepare($query))
{
$statement->bind_param("i", $user_id);
$statement->execute();
$statement->store_result();
if ($statement->num_rows > 0)
{
return ????????;
}
}
store_result应该返回一个mysqli_result对象。 使用fetch_all
的方法mysqli_result
得到的结果作为关联数组。
if ($statement = $this->mysqli->db->prepare($query))
{
$statement->bind_param("i", $user_id);
$statement->execute();
$statement->get_result();
if ($statement->num_rows > 0)
{
return $statement->fetch_assoc();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.