$sth = mysqli_query($conn, "SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
Funkce json_encode potřebuje PHP>=5.2 a php-json balíček – jak je uvedeno zde
POZNÁMKA :mysql je zastaralý od PHP 5.5.0, použijte mysqli místo toho rozšíření https://php.net/manual/en/migration55.deprecated.php
.