An error occurred while connecting to the database. in PHP, the current date of the system was obtained, but a problem occurred while matching the date type data in the database.
$ Link = mysql_connect ('localhost', 'root', 'root ');
If (! $ Link ){
Die ('connection failed'. mysql_error ());
}
// Echo "detailed date and time:". date ("Y-m-d H: I: s ");
$ Day = date ("Y-m-d"); // read the current time
Echo $ day ."
";
// $ Day1 = datatime ($ day );
Mysql_select_db ('pm25', $ link) or die ('pm25'. mysql_error ());
$ Result = mysql_query ("select * from ceshi where data = 'day '");
Echo'
';Echo'
| PM2.5 value |
Date |
Time | ';While ($ row = mysql_fetch_row ($ result )){Echo'
';Foreach ($ row as $ data ){Echo'
| '. $ Data .' | ';}Echo'
';}Echo'
';
Mysql_free_result ($ result );
Mysql_close ($ link );
However, no query results are displayed on the page:
Reply to discussion (solution)
$ Result = mysql_query ("select * from ceshi where data = 'day '");
Should be
$ Result = mysql_query ("select * from ceshi where data = '$ day '");
Thanks for the solution. but I want to ask how to intercept the current system time as the whole point? If the current time is 17:56:00, but I want to 17:00:00,
Date ("H: 00: 00 ")
Thank you, but how can I add or subtract time when I get the current time?
$ Day = date ("Y-m-d") + 1;
The result is not of the date type.