I got problem by getting date value from mysql through php. After I added the date, then no thing returned. What's the error of the code?
The column datatype is DateTime in mysql.
After output as Json, I use the Json formatter online one, and it said it is not valid Json. why?
try {
$conn = new PDO("mysql:host=host;dbname=db", "username", "pwd!");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$Ticker = htmlspecialchars($_GET["Ticker"]);
$Today = date('Ymd');
$result = $conn->prepare("SELECT Ticker, date(dateOfRelease) as 'Release date', Amount FROM TradeQuote WHERE Ticker='$Ticker' GROUP BY Date(dateOfRelease)");
$result = $result->fetchAll();
$temp = array();
foreach($result as $r) {
$temp[] = array('Ticker' => (string) $r['Ticker'], 'Release Date' => (date) $r['Release date'], 'Price' => (string) $r['Price'], 'Amount' => (string) $r['Amount']);
}
$table = $temp;
$jsonTable = json_encode($table);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo $jsonTable;
?>