Search code examples
mysqlzend-frameworkzend-db-table

How to insert into a table with NOW() in pdo_mysql


I am trying to use mysql NOW() function when I insert a record with Zend_Db but it is not working it seems. //$transaction is a very normal Zend_Db_Table object

$transaction->insert(array('date_created' => 'NOW()')); //inserted 0000-00-00 00:00:00

$transaction->insert(array('date_created' => '2010-12-12 12:12:12')); //inserted 2010-12-12 12:12:12

I am pretty sure I could do it using

$transaction->query()

But was wondering what was wrong with my first approach. Also NOW() does work on the server when in phpmyadmin.

All this on ubuntu server.


Solution

  • Try new Zend_Db_Expr('NOW()') instead of the string NOW()