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
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

Edited by Destramic
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.