2009年4月1日星期三

Re: [fw-db] Storing a Zend_Date in a Zend_Db_Table

There are two ways:

Eighter use getTimestamp to store the date as unix timestamp. Note that
databases as also Zend_Date supports negative timestamps and timestamps
beyond 32bit integer.

Or use toString() and get the format you want to have manually...
(toString('dd.MM.yyyy HH:mm:ss') for example)

There are issues to add dbagnostic date format to Zend_Db, but they are
actually not solved and have not much users which voted for them.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Daryl Handley" <darylhandley@gmail.com>
To: <fw-db@lists.zend.com>
Sent: Thursday, April 02, 2009 1:37 AM
Subject: [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
>

没有评论: