|
Prev: [PHP-DB]problem in creating the ibm_db2 extension
Next: problem in creating the ibm_db2 extension
From: Jason Pruim on 30 Apr 2008 11:29 Okay... So I know this should be simple... Trying to store a timestamp in a MySQL database... The timestamp I am making like so: $modifiedTimestamp = time(); and then just $sql = "Update `mytable` set timestamp='$modifiedTimestamp' where Record='1'"; Simple right? Not quite...in my database it's storing a "0" in the timestamp field which is a int(10) field. I have googled, and searched manuals, but have not been able to figure out what is going on.... Any Ideas? -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim(a)raoset.com
From: Stut on 30 Apr 2008 11:35 On 30 Apr 2008, at 16:29, Jason Pruim wrote: > Okay... So I know this should be simple... > > Trying to store a timestamp in a MySQL database... The timestamp I > am making like so: $modifiedTimestamp = time(); > > and then just $sql = "Update `mytable` set > timestamp='$modifiedTimestamp' where Record='1'"; > > Simple right? Not quite...in my database it's storing a "0" in the > timestamp field which is a int(10) field. > > I have googled, and searched manuals, but have not been able to > figure out what is going on.... > > Any Ideas? timestamp is a reserved word. Try putting it in backticks. -Stut -- http://stut.net/
From: Jason Pruim on 30 Apr 2008 11:38 On Apr 30, 2008, at 11:35 AM, Stut wrote: > On 30 Apr 2008, at 16:29, Jason Pruim wrote: >> Okay... So I know this should be simple... >> >> Trying to store a timestamp in a MySQL database... The timestamp I >> am making like so: $modifiedTimestamp = time(); >> >> and then just $sql = "Update `mytable` set >> timestamp='$modifiedTimestamp' where Record='1'"; >> >> Simple right? Not quite...in my database it's storing a "0" in the >> timestamp field which is a int(10) field. >> >> I have googled, and searched manuals, but have not been able to >> figure out what is going on.... >> >> Any Ideas? > > timestamp is a reserved word. Try putting it in backticks. Okay, so I did a really crappy job at my sudo code... The field name is actually Last_Updated. so my update code looks like this: Last_Updated='$modifiedTimestamp' *Slaps his wrist... Bad copy/paste! BAD!!! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim(a)raoset.com
From: "YVES SUCAET" on 30 Apr 2008 11:47 Hi Jason, It's not because you create a date/time value that you automatically have an integer-value. You need to specify first that you want the date/time value converted to an integer value first. See http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp for an example of how to do this. Actually, by using this function, you probably don't even need to create the $modifiedTimestamp variable anymore. You can just write your SQL query as follows: $sql = "Update `mytable` set timestamp=UNIX_TIMESTAMP() where Record='1'"; HTH, Yves ------ Original Message ------ Received: Wed, 30 Apr 2008 10:39:11 AM CDT From: Jason Pruim <japruim(a)raoset.com> To: Stut <stuttle(a)gmail.com>Cc: php-db(a)lists.php.net Subject: Re: [PHP-DB] Timestamps On Apr 30, 2008, at 11:35 AM, Stut wrote: > On 30 Apr 2008, at 16:29, Jason Pruim wrote: >> Okay... So I know this should be simple... >> >> Trying to store a timestamp in a MySQL database... The timestamp I >> am making like so: $modifiedTimestamp = time(); >> >> and then just $sql = "Update `mytable` set >> timestamp='$modifiedTimestamp' where Record='1'"; >> >> Simple right? Not quite...in my database it's storing a "0" in the >> timestamp field which is a int(10) field. >> >> I have googled, and searched manuals, but have not been able to >> figure out what is going on.... >> >> Any Ideas? > > timestamp is a reserved word. Try putting it in backticks. Okay, so I did a really crappy job at my sudo code... The field name is actually Last_Updated. so my update code looks like this: Last_Updated='$modifiedTimestamp' *Slaps his wrist... Bad copy/paste! BAD!!! -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim(a)raoset.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
From: Jason Pruim on 30 Apr 2008 11:54 Hi Yves, Thanks for the tip, that worked, I think I'll use that from now on.. Just out of curiosity though, any idea why it wasn't working as I was writing it :) On Apr 30, 2008, at 11:47 AM, YVES SUCAET wrote: > Hi Jason, > > It's not because you create a date/time value that you automatically > have an > integer-value. You need to specify first that you want the date/time > value > converted to an integer value first. > > See > http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp > for an example of how to do this. > > Actually, by using this function, you probably don't even need to > create the > $modifiedTimestamp variable anymore. You can just write your SQL > query as > follows: > > $sql = "Update `mytable` set timestamp=UNIX_TIMESTAMP() where > Record='1'"; > > HTH, > > Yves > > ------ Original Message ------ > Received: Wed, 30 Apr 2008 10:39:11 AM CDT > From: Jason Pruim <japruim(a)raoset.com> > To: Stut <stuttle(a)gmail.com>Cc: php-db(a)lists.php.net > Subject: Re: [PHP-DB] Timestamps > > > On Apr 30, 2008, at 11:35 AM, Stut wrote: > >> On 30 Apr 2008, at 16:29, Jason Pruim wrote: >>> Okay... So I know this should be simple... >>> >>> Trying to store a timestamp in a MySQL database... The timestamp I >>> am making like so: $modifiedTimestamp = time(); >>> >>> and then just $sql = "Update `mytable` set >>> timestamp='$modifiedTimestamp' where Record='1'"; >>> >>> Simple right? Not quite...in my database it's storing a "0" in the >>> timestamp field which is a int(10) field. >>> >>> I have googled, and searched manuals, but have not been able to >>> figure out what is going on.... >>> >>> Any Ideas? >> >> timestamp is a reserved word. Try putting it in backticks. > > > Okay, so I did a really crappy job at my sudo code... The field name > is actually Last_Updated. > > so my update code looks like this: Last_Updated='$modifiedTimestamp' > > *Slaps his wrist... Bad copy/paste! BAD!!! > > -- > > Jason Pruim > Raoset Inc. > Technology Manager > MQC Specialist > 3251 132nd ave > Holland, MI, 49424-9337 > www.raoset.com > japruim(a)raoset.com > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim(a)raoset.com
|
Next
|
Last
Pages: 1 2 3 Prev: [PHP-DB]problem in creating the ibm_db2 extension Next: problem in creating the ibm_db2 extension |