php mysql json example

$link = mysql_pconnect(“localhost”, “root”, “”) or die(“Could not connect”);
mysql_select_db(“cdcol”) or die(“Could not select database”);
 
$arr = array();
$rs = mysql_query(“SELECT id, titel FROM cds”);
 
while($obj = mysql_fetch_object($rs)) {
    $arr[] = $obj;
}
 
echo ‘{“sample”:’.json_encode($arr).’}’;
?>