Destramic Posted May 30, 2015 Share Posted May 30, 2015 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 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 30, 2015 Share Posted May 30, 2015 (edited) You use REPLACE for updating values within existing rows If are inserting a record but don't want duplicate records use INSERT IGNORE Edited May 30, 2015 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Barand Posted May 30, 2015 Share Posted May 30, 2015 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 1 Quote Link to comment Share on other sites More sharing options...
Destramic Posted May 30, 2015 Author Share Posted May 30, 2015 (edited) 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 May 30, 2015 by Destramic Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.