Hello @kartik,
Use this:
$sth = mysqli_query($conn, "SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
The function json_encode needs PHP >= 5.2 and the php-json package
NOTE: mysql is deprecated as of PHP 5.5.0, use mysqli extension instead