简体   繁体   中英

Problems with timestamp on mysql (php)

I have made the following table on mysql to save the time that a client visit the page:

CREATE TABLE `visitas` ( 
 `**idv**` int(11) AUTO_INCREMENT, 
 `**fecha**` timestamp **DEFAULT CURRENT_TIMESTAMP**,
 `**ip**` varchar(15)  
 PRIMARY KEY (`**idv**`))

On php I run the next query:

mysql_query("INSERT INTO `visitas`(`ip`) VALUES ('$ip')");

The problem is that mysql save the time of the United States, and I want the time of Mexico.

I have tryed:

mysql_query("SET time_zone = '-06:00'");

but it doesnt take effect.

Please help me to make that mysql automatically save the time that i want.

To set timezones with mysql, use SET GLOBAL time_zone = '-06:00';

or just set it with php

mysql_query("insert into visitas(ip, timestamp) values ('$ip', '". date('Y-m-d H:i:s', time()) ."');

also, dont use mysql , look at mysqli or PDO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM