![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi guys, Total noob here, trying to figure out how to build a database ![]() Problem I want two fields in my tablet: 1) showing when a record was created & 2) showing when the record was last updated #1 I can figure out. #2 is a bugger. I've tried TIMESTAMP, and a few other types, but whenever I update the record, nothing happens :/ Suggestions? Thanks ![]() I explicitly set it in (in this case ) PHP using the function |
#3
| |||
| |||
|
|
I explicitly set it in (in this case ) PHP using the function $time=date("Y-m-d H:i:s"); |
But what do you do if your input doesn't come from
#4
| |||
| |||
|
|
I explicitly set it in (in this case ) PHP using the function $time=date("Y-m-d H:i:s"); Cool, I get that But what do you do if your input doesn't come fromPHP? Lets say it's being manually typed into the database? In SQL I might make a trigger, that notes the date of last modification, but I'd sure love for the database to keep track of it for me, no matter when or how an entry is updated. Thanks though ![]() see the next part of my post. ...set last_access=NOW() |
#5
| |||
| |||
|
|
Hi guys, Total noob here, trying to figure out how to build a database ![]() Problem I want two fields in my tablet: 1) showing when a record was created & 2) showing when the record was last updated #1 I can figure out. #2 is a bugger. I've tried TIMESTAMP, and a few other types, but whenever I update the record, nothing happens :/ |
#6
| |||
| |||
|
|
On Tue, 20 Sep 2011 20:01:21 +0200, ThomasH wrote: Hi guys, Total noob here, trying to figure out how to build a database ![]() Problem I want two fields in my tablet: 1) showing when a record was created& 2) showing when the record was last updated #1 I can figure out. #2 is a bugger. I've tried TIMESTAMP, and a few other types, but whenever I update the record, nothing happens :/ Section 10.3.1.1 of the manual. The abbreviated answer is that there are two controls for automatically handling TIMESTAMP columns. 1) you've figured out ( my_ts_col TIMESTAMP DEFAULT CURRENT_TIMESTAMP ). 2) auto updating whenever the record changes uses the following format: my_ts_col TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP turns off auto initialization, but turns on updates on UPDATE. (If you're using traditional sql, this will also get you an error because a zero timestamp is an error, and there's another couple of settings that can cause problems with this as well, but they're rare alone.) There's some additional quirks that these are *automatically* both turned on for the first timestamp column in a record layout. If you let the first column do that, you'll get the behavior of having both turned on. If you explicitly turn on the DEFAULT version, that turns off the autoupdate for that column. If you set the column to nullable you'll ruin the default automatic settings and I think the ON UPDATE as well. |

#7
| |||
| |||
|
|
On 20-09-2011 23:32, Peter H. Coffin wrote: On Tue, 20 Sep 2011 20:01:21 +0200, ThomasH wrote: Hi guys, Total noob here, trying to figure out how to build a database ![]() Problem I want two fields in my tablet: 1) showing when a record was created& 2) showing when the record was last updated #1 I can figure out. #2 is a bugger. I've tried TIMESTAMP, and a few other types, but whenever I update the record, nothing happens :/ Section 10.3.1.1 of the manual. The abbreviated answer is that there are two controls for automatically handling TIMESTAMP columns. 1) you've figured out ( my_ts_col TIMESTAMP DEFAULT CURRENT_TIMESTAMP ). 2) auto updating whenever the record changes uses the following format: my_ts_col TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP turns off auto initialization, but turns on updates on UPDATE. (If you're using traditional sql, this will also get you an error because a zero timestamp is an error, and there's another couple of settings that can cause problems with this as well, but they're rare alone.) There's some additional quirks that these are *automatically* both turned on for the first timestamp column in a record layout. If you let the first column do that, you'll get the behavior of having both turned on. If you explicitly turn on the DEFAULT version, that turns off the autoupdate for that column. If you set the column to nullable you'll ruin the default automatic settings and I think the ON UPDATE as well. Wow, that's great - I think I have something to go on now... I predict some studying in my future. Thanks to both repliers ![]() |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Hi again, So I took a look at http://dev.mysql.com/doc/refman/5.0/en/timestamp.html and added a column to my db using: ALTER TABLE MyDB ADD lastmodified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; Still - if I edit the contents of another field in the row, "lastmodified" remains unchanged. Have tried updating with both the default 000-00-00 value and one set to now, to get the ball rolling - no dice :/ Any further advice? Thomas |
#10
| |||
| |||
|
|
Hi again, So I took a look at http://dev.mysql.com/doc/refman/5.0/en/timestamp.html and added a column to my db using: ALTER TABLE MyDB ADD lastmodified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; Still - if I edit the contents of another field in the row, "lastmodified" remains unchanged. Have tried updating with both the default 000-00-00 value and one set to now, to get the ball rolling - no dice :/ Any further advice? Thomas |
![]() |
| Thread Tools | |
| Display Modes | |
| |