Jump to content

timestamp on update


Destramic

Recommended Posts

 hey guys here is my table below:

CREATE TABLE IF NOT EXISTS `sessions` (
  `id` varchar(62) NOT NULL,
  `data` text NOT NULL,
  
`lifetime` int(10) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  
`modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) 
ENGINE=InnoDB

my problem is when i use  a replace into query

REPLACE INTO sessions (id, data, lifetime) VALUES ('1234', 'data here', '360')

whats happening is when replacing a row the created column is  always gets updated with the current timestamp...

 

which is because im using the replace into function....is there a way when existing the replace into, which updates a row for it not to update the created column?

 

thanks you

 

 

Link to comment
https://forums.phpfreaks.com/topic/296547-timestamp-on-update/
Share on other sites

Replace will DELETE then INSERT an new record if there is record there already with same key.

 

Try using INSERT...ON DUPLICATE KEY UPDATE instead

 

thanks for you post guys

INSERT INTO sessions (id, data, lifetime) 
VALUES (1, 'done it', '260') 
ON DUPLICATE KEY 
UPDATE data = 'done it', lifetime = '260

worked like a dream

Link to comment
https://forums.phpfreaks.com/topic/296547-timestamp-on-update/#findComment-1512864
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.