$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
output like this:
[
{"id":"31","name":"pruduct_name1","price":"98"},
{"id":"30","name":"pruduct_name2","price":"23"}
]
If you want another style, you can try this:
$row = $result->fetch_row()
$myArray[] = $row
output will like this:
[
["31","pruduct_name1","98"],
["30","pruduct_name2","23"]
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…