Here is the table of interest when exported via phpMyAdmin:
这是通过phpMyAdmin导出时感兴趣的表:
CREATE TABLE IF NOT EXISTS `users` (
`ip` varchar(20) NOT NULL,
`lastcheck` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Here is the query:
这是查询:
mysql_query("REPLACE INTO users SET ip = '$uip', lastcheck = '$tim'") or throwerror("part2 ".mysql_error());
$tim is set to be time();
$ tim设置为time();
Now for some reason lastcheck is still set as 0000-00-00 00:00:00.
现在由于某种原因,lastcheck仍然设置为0000-00-00 00:00:00。
Can anyone help? Thanks.
有人可以帮忙吗?谢谢。
2 个解决方案
#1
I am not sure if maybe I understand your problem, looking at column lastcheck declaration CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP that means when ever you update (ip = '$uip') this column an automatic date update will also happen lastcheck. Which mean you can write you update statment as follows :
我不确定我是否理解你的问题,查看列lastcheck声明CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP这意味着当你更新(ip ='$ uip')这一列时,自动更新日期也会发生在lastcheck上。这意味着你可以写下更新语句如下:
REPLACE INTO users SET ip = '$uip';
That should also update the lastcheck field, and I think it's better to use the mysql date functions to store your date/time than writing them in php and saving them as string in the database...
这也应该更新lastcheck字段,我认为最好使用mysql日期函数来存储你的日期/时间,而不是在php中编写它们并将它们保存为数据库中的字符串...
#2
try using date('Y-m-d H:i:s') in stead of time()
尝试使用日期('Y-m-d H:i:s')而不是时间()
time() in php returns a unix timestamp and that isn't a valid insert for MyySQL datetime
php中的time()返回一个unix时间戳,这不是MyySQL datetime的有效插入
hope this helps
希望这可以帮助
#1
I am not sure if maybe I understand your problem, looking at column lastcheck declaration CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP that means when ever you update (ip = '$uip') this column an automatic date update will also happen lastcheck. Which mean you can write you update statment as follows :
我不确定我是否理解你的问题,查看列lastcheck声明CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP这意味着当你更新(ip ='$ uip')这一列时,自动更新日期也会发生在lastcheck上。这意味着你可以写下更新语句如下:
REPLACE INTO users SET ip = '$uip';
That should also update the lastcheck field, and I think it's better to use the mysql date functions to store your date/time than writing them in php and saving them as string in the database...
这也应该更新lastcheck字段,我认为最好使用mysql日期函数来存储你的日期/时间,而不是在php中编写它们并将它们保存为数据库中的字符串...
#2
try using date('Y-m-d H:i:s') in stead of time()
尝试使用日期('Y-m-d H:i:s')而不是时间()
time() in php returns a unix timestamp and that isn't a valid insert for MyySQL datetime
php中的time()返回一个unix时间戳,这不是MyySQL datetime的有效插入
hope this helps
希望这可以帮助