$mysqli = new mysqli('localhost','user','password','myDatabaseName');
$myArray = array();
if ($result = $mysqli->query("SELECT * FROM phase1")) {
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$myArray[] = $row;
}
echo json_encode($myArray);
}
$result->close();
$mysqli->close();
$row = $result->fetch_array(MYSQLI_ASSOC)
$myArray[] = $row
вывод такой:
[
{"id":"31","name":"pruduct_name1","price":"98"},
{"id":"30","name":"pruduct_name2","price":"23"}
]
Если вы хотите другой стиль, вы можете попробовать это:
$row = $result->fetch_row()
$myArray[] = $row
вывод будет выглядеть так:
[
["31","pruduct_name1","98"],
["30","pruduct_name2","23"]
]