2009年4月1日星期三

[fw-db] Storing a Zend_Date in a Zend_Db_Table

I'm trying to store a date in a db table (using Oracle) and it fails telling me.

ORA-01858: a non-numeric character was found where a numeric was expected

My code looks something like this

        $paymentData = array(   
            'DATE' => Zend_Date::now(),
            'USERID' => $userId,
            'AMOUNT' => $amount       
        );
        $paymentDbTable = new PaymentDbTable();
        $paymentDbTable->insert($paymentData);

I've also tried using Zend_Date::now()->getIso() and it doesn't like that much either (ORA-01861: literal does not match format string).

I have a couple of workarounds but I don't really like either of them because they kind of tie it to Oracle (format into a string literal that Oracle likes or use a Zend_Db_Expr('SYSDATE'). In Java this was pretty simple and you just pass the date and the adapter layer figures out what to do. I've got to think there must be an easy db agnostic way to do it in Zend as well.

Thanks
Daryl

没有评论: