I am trying the simple insert:
$data = array
(
'whatever' => 'nevermind',
'etc' => 'more data',
'updated_on' => new Zend_Db_Expr('NOW()')
);
$this->getDbTable()->insert( $data );
Everything gets inserted correctly, but updated_on is null. Am I doing something wrong? I understand it may be not easy to determine the problem from what I said, but maybe you could suggest at least how could I debug this? Thanks in advance
p.s. database is mySQL and column is DATETIME, and if I connect to mySQL and manually try the insert or update NOW(), it does work.
Update
Using Profiler, I get the following output:
INSERT INTO `db_table` (`column1`, `column2`, `column3`, `column4`, `column5`, `column6`, `column_datetime`, `column7`) VALUES (?, ?, ?, ?, ?, ?, NOW(), ?)
Array
(
[1] => column1 data
[2] => column2 data
[3] => column3 data
[4] => column4 data
[5] => column5 data
[6] => column6 data
[7] => column7 data
)
To my knowledge, everything is fine here :\
Update2: Nevermind, I got it working. Problem was entirely different.
Based solely on the code you are posting, this should work.
Since it does not, you should use the profiler to debug the query:
$db = $this->getDbTable();
$adapter = $db->getAdapter();
$adapter->getProfiler()->setEnabled(true);
$data = array
(
'whatever' => 'nevermind',
'etc' => 'more data',
'updated_on' => new Zend_Db_Expr('NOW()')
);
$db->insert( $data );
print $adapter->getProfiler()->getLastQueryProfile()->getQuery();
print_r($adapter->getProfiler()->getLastQueryProfile()->getQueryParams());
$adapter->getProfiler()->setEnabled(false);