Home >Backend Development >PHP Tutorial >PHP learning to connect to database + date processing
This time I bring you a code, about using PHP to connect to the database and process dates. Interested friends can come and learn about it!
php connects to the database, and the date processing function code is as follows :
$conn=mysql_connect("10.0.10.0:0000","root","123456") or die("数据库连接失败").mysql_error();//连接数据库 mysql_select_db("database"); $querry1 = "SELECT * FROM `crm_module_27` where field1='" . $ORDER_ID . "'"; $cursor1 = mysql_query($querry1); if ($ROW = mysql_fetch_array($cursor1)) { $startwork=$ROW['field3']; } $now=date("Y-m-d");//日期处理 $nowy=date("y"); $nowy1=date("y",strtotime("-1 year")); $nowy2=date("y",strtotime("+1 year")); $nowm=date("m"); $nowm1=date("m",strtotime("-1 month")); $nowm2=date("m",strtotime("+1 month")); $nowd=date("d"); $startworky=date("y",strtotime($startwork)); $startworkm=date("m",strtotime($startwork)); $startworkd=date("d",strtotime($startwork));
If you want to know more PHP tutorials, please pay attention to PHP Video Tutorials on the PHP Chinese website!
The above is the detailed content of PHP learning to connect to database + date processing. For more information, please follow other related articles on the PHP Chinese website!