繁体   English   中英

返回mysqli结果作为数组

[英]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得到的结果作为关联数组。

看到此链接http://us2.php.net/manual/en/class.mysqli-result.php

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM