PHP - JSON没有输出

I have written a code that outputs all termins i have the day. The calendar for this is already finished. But the program output, I want to use with python don't work.

My code:

<?php

mysql_connect(deleted);
mysql_select_db("DB1367141")

$day = date("d");
$month = date("m");
$year = date("Y");

$result = mysql_query("SELECT * FROM entries WHERE day = '$day' AND month = '$month' AND year = '$year' ORDER BY hour DESC, minute");

$array = {};

while($obj = mysql_fetch_object($result))
{
    if($obj->hour != "--")
        $hour = splitf("%02d", $obj->hour);
    else
        $hour = $obj->hour;

    if($obj->minute != "--")
        $minute = splitf("%02d", $obj->minute)
    else
        $minute = $obj->minute;

    array_push($array, {"hour":$hour, "minute":$minute, "text":$obj->tex});
}

var_dump($array);
echo json_encode($array);

?>

But if i run it, it neither outputs the array than an "echo('hi');"

I tried out to put this echo at the begin, at the end and in the middle. But the output is the same: nothing

In another forum I found out that I have to write:

$array = array();

But the output is the same: nothing.


i tryed both, right syntax and error report. as i changed $array = array(); nothing changed. i added two lines in my .htaccess to get better error report, and it outputed a 500 Internal Server Error.

Might I recommend you try converting your date storage to timestamps in the name of simplicity. That way you only need to check that the entry is between the first and last second of "today".

You'd save yourself quite a lot of hassle and if you really need to output as in that JSON layout could just parse the timestamp using:

while($obj = mysql_fetch_object($result)) {
    $array[] = array(
        'hour' => date('H', $obj->timestamp,
        'minute' => date('i', $obj->timestamp,
        'text' => $obj->tex
    );
}
echo json_encode($array);

date('n', strtotime($strTimestamp));

To instantiate a blank array in PHP is

$array = array();

EDIT: as enricog said :)

Also, for simplicity sake, array_push isn't needed, I'd just use:

$array[] = array("hour" => $hour, "minute" => $minute, "text" => $obj->tex);