3

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.

Charles
  • 50,943
  • 13
  • 104
  • 142
Sejanus
  • 3,253
  • 8
  • 39
  • 52

1 Answers1

7

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);
Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
  • Thanks! With a little googling I found out it must be $db = $this->getDbTable()->getAdapter(); because Zend_Db_Table has no method getProfiler(). Anyhow, once I got it working, the query profiler printed seems to be ok :( – Sejanus Feb 08 '11 at 10:42
  • 1
    Very strange. Have you tried editing the datetime column to a date or text column? Interested in what the data is actually trying to insert. As a last measure, you could insert it by hand, although it is not *really* a solution: `date("Y-m-d H:i:s")` – Aron Rotteveel Feb 08 '11 at 10:47