$sth = mysqli_query($conn, "SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
La función json_encode
necesita PHP>=5.2 y php-json paquete:como se menciona aquí
NOTA :mysql
está en desuso a partir de PHP 5.5.0, use mysqli
extensión en lugar de http://php.net/manual/en/migration55.deprecated.php
.