<?php
$host = "hostname";
$user = "dbuser";
$pw = "dbpw";
$db = "dbname";
$con = mysqli_connect($host,$user,$pw) or die(mysqli_error());
mysqli_select_db($con,$db) or die(mysqli_error());
mysqli_query($con,"SET CHARACTER SET utf8");
mysqli_query($con,"SET NAMES 'utf8'");
$q = mysqli_query($con,"SELECT * FROM mytable order by xxxx ASC") or die(mysqli_error($con));
$rows = array();
while($r = mysqli_fetch_assoc($q)) ' = culumn name -> value
{
$rows[] = $r;
}
print json_encode($rows);
?>