Ciao a tutti....

ho un dilemma... sto estraendo da una tabella MySQL dei dati direttamente in formato JSON, la SELECT ritorna correttamente un risultato pero' nel file PHP pare che all'estrazione del dato per inserirlo nella variabile $json_string sembra vuoto perche' se tento di scrivere a file un var_dump per vedere il contenuto di questa $json_string, nel file non viene scritto nulla...eppure la select ritorna correttamente un record.

Qualche idea?...... di seguito il codice....

<?php
include("dbconfig.php");

$myfile = "c:\\debug.txt";
if (!file_exists($myfile))
$fh = fopen($myfile, 'w') or die("can't open file.");
else
$fh = fopen($myfile, 'a') or die("can't open file.");

// connect to the MySQL database server
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());

// select the database
mysql_select_db($database, $db) or die("Error connecting to db.");

// getting data
$SQL = "SELECT CONCAT(\"[{aeroporti:\", GROUP_CONCAT(CONCAT(\"{id:\",id,\"\"), CONCAT(\",description:'\",description,\"'}\")), \"}]\") as json_string FROM tv_airports ORDER BY id";
$result = mysql_query($SQL, $db) or die(mysql_error());
$SQL .= "\n";
fwrite($fh, $SQL);
$num_rows = mysql_affected_rows();
fwrite($fh, $num_rows."\n");
fclose($fh);

$json_string = "";
if ($num_rows > 0) {
$row = mysql_fetch_array($result, MYSQL_BOTH) or die(mysql_error()));
$json_string = utf8_encode($row[0]);
fwrite($fh, var_dump($json_string));
}
mysql_close($db);

fwrite($fh, "\n");
fclose($fh);

echo $json_string;
?>

Grazie a tutti in anticipo!!

Ciao,
Luigi