MySQL Database'den JSON Veri Çekmek
<?
function mysql2json($resultSet,$debug="false"){
$numberRows=0;
$arrfieldName=array();
$json="{\n'data': [\n";
while (false !==($meta = mysql_fetch_field($resultSet))) {
array_push(&$arrfieldName,$meta->name);
}
while($row=mysql_fetch_array($resultSet, MYSQL_NUM)) {
$json.="{\n";
for($r=0;$r < count($arrfieldName);$r++) {
$json.="'".htmlspecialchars($arrfieldName[$r])."' : '".htmlspecialchars($row[$r])."',\n";
}
$json = trim($json,",\n");
$json.="\n},\n";
}
$json = trim($json,",\n");
$json.="]\n}";
if($debug===true) {
$json = "<pre>$json</pre>";
}
echo trim($json);
}
//Kullanımı
$db = mysql_query("select * from veriler");
mysql2json($db);
//FKA
?>
Linkback: https://www.buyuknet.com/mysql-databaseden-json-veri-cekmek-t21127.0.html