Hi,

Try using  Zend_Db_Expr:

$data = array(
  'orders_status' => (int)$orders_status,
  'last_modified' => new Zend_Db_Expr('NOW()'));

Regards
    Håkan Medin



On Tue, Jun 16, 2009 at 2:46 AM, Kendall Bennett
<kenda...@amainhobbies.com>wrote:

> Ok, I am struggling to find a solution to this problem using the Zend_Db
> interface. I want to do the following:
>
> $data = array(
>   'orders_status' => (int)$orders_status,
>   'last_modified' => 'now()');
> $db->update(TABLE_ORDERS, $data, 'orders_id = ' . (int)$orders_id)
>
> But the update() method does not understand the now() string and sends it
> in the SQL as a string literal, because it gets quoted. Instead I have to do
> this:
>
> $now = date('Y-m-d H:i:s');
> $data = array(
>   'orders_status' => (int)$orders_status,
>   'last_modified' => $now);
> $db->update(TABLE_ORDERS, $data, 'orders_id = ' . (int)$orders_id)
>
> This works of course, but the problem is I really need to set the value to
> the current date time that the query is executed, so it gets the date time
> stamp on the DB server, not on the PHP application server. Even though the
> values are going to be close, if the database is on a separate server the
> timestamps can be slightly different. Worse, if this code was running on a
> server farm for the PHP servers, each server could have slightly different
> timestamps, and if you are relying on the timestamps to be sequential, you
> can run into problems.
>
> Now clearly I can hand code the SQL inserts, but that defeats the purpose
> of having the insert() function. In our existing code the insert() wrapper
> special cases the now() string, and passes it through literally.
>
> Is there any way to do that with Zend_Db?
>
> Regards,
>
> *Kendall Bennett, CEO
> *A Main Hobbies
> 424 Otterson Drive, Suite 160
> Chico, CA 95928
> 1-800-705-2215 (Toll-Free)
> 1-530-894-0797 (Int'l & Local)
> 1-530-894-9049 (Fax)
> *http://www.amainhobbies.com*
>

Reply via email to