Home » Database » DB_DataObject » Bug #8261
Using the NOW() function
Details
| Request #8261 | Using the NOW() function |
|---|---|
| Submitted | 2006-07-21 03:30 UTC |
| From | alegrand1 at gmail dot com |
| Status | Bogus |
| Package | DB_DataObject |
| PHP Version | 5.1.4 |
| OS | Apache |
| Roadmaps | (Not assigned) |
Comments
[2006-07-21 03:30 UTC] alegrand1 at gmail dot com
Description:
------------
Not very hard to explain this one. When trying to use MySQL's (I'm using 5.0.21) NOW() function on a timestamp column, to JUST update the timestamp and nothing else in the row, the function is wrapped in quotes within the SQL query and is parsed as a string rather than as a function, setting the timestamp column to: 0000-00-00 00:00:00
As far as I can tell, the only way around this would be to use PHP's date function, assuming the php server and mysql server were in the same timezone. This could cause problems.
What is needed is something to delimit a MySQL function, or a way to tell DataObjects not to wrap something in quotes, such as:
$table->last_update = '{NOW()}';
Test script:
---------------
$table = DB_DataObject::factory('table');
$table->get(id);
$table->last_update = 'NOW()';
$table->update();
Note that we can't use
$table->last_update = NOW();
Because then PHP will looking for the NOW() function.
Expected result:
----------------
SQL Query:
UPDATE table SET last_update = NOW() WHERE ( table.id = id )
Actual result:
--------------
SQL Query:
UPDATE table SET last_update = 'NOW()' WHERE ( table.id = id )