[SOLVED] table column value gets updated automatically

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

table column value gets updated automatically

Post by jasongr »

Hello I have the following table definition:

Code: Select all

CREATE TABLE session_info (
  SessionID INT UNSIGNED NOT NULL AUTO_INCREMENT,
  Param VARCHAR(255) NOT NULL,
  Expiration TIMESTAMP NOT NULL,
PRIMARY KEY (SessionID)
) ENGINE=MYISAM DEFAULT CHARSET=latin1;
I set the expiration using the following query:

Code: Select all

$expiration = time() + 7200;
UPDATE session_info SET Expiration = FROM_UNIXTIME($expiration) WHERE SessionID = 5;
I can check the database and I see that the expiration value has been changed, by calling:

Code: Select all

select UNIX_TIMESTAMP(Expiration) Expiration from session_info where SessionID = 5;
Later in the code I call the following query:

Code: Select all

UPDATE session_info SET Param= 'aaa' WHERE SessionID = 5;
After this query runs, I see that the Param values gets changed to 'aaa', BUT the Expiration column gets changed too -> to the current timestamp!, and the previous value has been lost!

Is this how things are suppose to happen?
I thought that the Expiration column shouldn't change.

thanks
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

thanks for the help
The link was very useful
Post Reply