0
我有這樣的PHP代碼:get_result() - > FETCH_ASSOC()總是返回1行
public function getcabang(){
$cabang = $this->conn->prepare("SELECT nama_cabang,alamat FROM cabang");
if ($cabang->execute()){
$cbg = $cabang->get_result()->fetch_assoc();
$cabang->close();
return $cbg;
} else {
return NULL;
}
}
,但它總是返回1行:
{"error":false,"cabang":{"nama_cabang":"Senayan","alamat":"Pintu 1 Senayan"}}
即使它有超過1排在表
'FETCH_ASSOC()'一次只返回一行。您需要迭代結果集以獲取所有行。 – jbafford