2010年6月14日星期一

Re: [fw-db] Need help REGARDING ZEND_DB MAX(ID)

On 06/14/2010 09:39 PM, Y D wrote:
> Hi,
>
> i am fairly new to ZEND and PHP...so it takes me hell of a time
> searching for small issues...
>
> the thing im facing problem is ZEND_DB....i find making queries in ZEND
> complicated...is there a way to simply make a query as a STRING and then
> execute it? like....
>
> $query = "SELECT /*bla*/ from /*bla bla*/ where /*bla bla bla*/";
> $connection(host,dbname....);
>
> then execute->($query, $connection);
>
> ??????????????????????
>
>
> im looking for MAX(columnName) ... in ORACLE it is easy to use it by a
> simple
> /*
> select NVL(MAX(INBOX_NUMBER),0)+1 MAXINNUM FROM ARC_DOCUMENT*/
>
> now i want to use this query in ZEND which is taking all day for me...
>
> this is the query i came up with
>
> $column = 'INBOX_NUMBER';
>
> $this->_name=$table;
> $select = $this->select()
> ->from($table, array(new Zend_Db_Expr('max('.$column.')
> ')));
>
> $results = $this->fetchAll($select);
> return $results;
>
>
>
> and this was its result
> /*
> Message: Specified column "INBOX_NUMBER" is not in the row*/
>
> but the table ARC_DOCUMENT has the column named INBOX_NUMBER..where as
> INBOX_NUMBER is not the PRIMARY KEY of the table ARC_DOCUMENT...and i
> don't want to put a sequence on it or anything..
>
>
> where am i going wrong????
>
> please find with this email, the code for my model function and form
> part where i am using it
>
> please help...before i start hating ZEND or get killed by my manager :-Z
>
>
> --
> Regards,
> YD

MAX()+1 is a bad idea because you may get the wrong value when there are
multiple concurrent clients.
Use sequences in Oracle and get the value by lastSequenceId() method.
See the manual for more information.

--
Nilesh Govindarajan
Facebook: http://www.facebook.com/nilesh.gr
Twitter: http://twitter.com/nileshgr
Website: http://www.itech7.com
Cheap and Reliable VPS Hosting: http://j.mp/arHk5e

没有评论: