PHP绑定结果并获取多行(数组)

PHP绑定结果并获取多行(数组),php,mysql,Php,Mysql,我对php和mysql相当陌生。我正在尝试从php创建RESTAPI,因为我的服务器没有安装mysqlnd,所以我必须使用bind\u result和fetch $stmt = $this->conn->prepare("SELECT * from d WHERE d.id = ?"); $stmt->bind_param("i", 1); if($stmt->execute()){ $stmt->bind_result($a, $b, $c); $

我对php和mysql相当陌生。我正在尝试从php创建RESTAPI,因为我的服务器没有安装
mysqlnd
,所以我必须使用
bind\u result
fetch

$stmt = $this->conn->prepare("SELECT * from d WHERE d.id = ?");
$stmt->bind_param("i", 1);
if($stmt->execute()){
    $stmt->bind_result($a, $b, $c);
    $detail = array();  
    while($stmt->fetch()){      

        $detail["a"] = $a;
        $detail["b"] = $b;
        $detail["c"] = $c;
    }

    $stmt->close();
    return $response;
} else {
    return NULL;
}
上面的代码可以工作,但一次只能返回一行信息

例如,如果语句返回:

a    b    c
1   test  test
1   test1 test1
它只会回来

a: 1
b: test1
c: test1
它应该在哪里:

{
    a: 1
    b: test
    c: test
},
{
    a: 1
    b: test1
    c: test1
}

如果要覆盖它们,可以执行以下操作:

$detail = array();  
while($stmt->fetch())
{           
    $temp = array():
    $temp["a"] = $a;
    $temp["b"] = $b;
    $temp["c"] = $c;
    $detail[] = $temp;
}
或者直接将它们附加到另一个维度:

$detail = array();  
while($stmt->fetch()) {           
    $detail[] = array('a' => $a, 'b' => $b, 'c' => $c);
      //   ^ add another dimension
}

您在while循环的每次迭代中都要替换
$detail
。您需要通过
$detail[][“a”]=$a
等方式追加。您是在共享网络主机上还是在自己的邮箱中?有没有安装mysqlnd的方法?