views:

24

answers:

1

Hello,

I am trying to add an entry to an Oracle table which has a date field. So far, I've only been able to do it like this:

$createdDate = $entry->createdDate->toString('yyyy-MM-dd');
$data = array(
    'ID' => $entry->id,
    'STATE' => $entry->state,        
    'CREATED_DATE' => new Zend_Db_Expr("to_date('$createdDate', 'YYYY-MM-DD')")
);
$this->_getGateway()->insert($data);

Is there a better way? This solution smells dirty to me.

A: 

You should be able to do this instead:

$createdDate = $entry->createdDate->toString('yyyy-MM-dd');
$data = array(
    'ID' => $entry->id,
    'STATE' => $entry->state,        
    'CREATED_DATE' => new Zend_Db_Expr("date '$createdDate'")
);
$this->_getGateway()->insert($data);

The only difference is the use of an ANSI date literal in line 5.

Tony Andrews