Database connection problems-php Tutorial

Source: Internet
Author: User
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' ';While ($ row = mysql_fetch_row ($ result )){Echo' ';Foreach ($ row as $ data ){Echo' ';}Echo' ';}Echo'
PM2.5 value Date Time
'. $ Data .'
';
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.