PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #8261

Using the NOW() function

Details

Request #8261Using the NOW() function
Submitted2006-07-21 03:30 UTC
Fromalegrand1 at gmail dot com
StatusBogus
PackageDB_DataObject
PHP Version5.1.4
OSApache
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 )