$sth = mysqli_query($conn, "SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
De functie json_encode heeft PHP>=5.2 en de php-json . nodig pakket - zoals vermeld hier
OPMERKING :mysql is verouderd vanaf PHP 5.5.0, gebruik mysqli extensie in plaats daarvan https://php.net/manual/en/migration55.deprecated.php
.