如何从sql查询中获取一个对象数组

时间:2016-05-17 10:01:20

标签: php mysql

我的代码是

$sql = 'select * from table;' $res = $connection->query($sql);
while($row = mysqli_fetch_row($res){'tackle output'};

获取对象

while($row = $res->fetch_object()){'tackle output'};

问题:我需要做些什么才能获得一个对象数组,因此我的输出就是

$data[$row[0]]= fetch_object();

3 个答案:

答案 0 :(得分:2)

试试这个:

$data = array();
while($row = $res->fetch_object()){
      $data[] = $row;
}

答案 1 :(得分:1)

一样使用它
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
Warning: get_headers(): Failed to enable crypto in 
Warning: get_headers(https://200.35.78.130/): failed to open stream: operation failed in /

答案 2 :(得分:0)

你想要全部取得 你可以做到这一点 http://php.net/manual/en/mysqli-result.fetch-all.php