2009年12月5日星期六

Re: [fw-db] lastInsertId() not working?

You are certain that the primary key is autoincrement?

On 12/5/09, waldenguy <omegamatt2002@hotmail.com> wrote:
>
> Hi,
>
> I've been working through the book 'Pro Zend Framework techniques' and have
> found it quite enjoyable so far. I have worked with the Zend Framework
> before so was just going through it to reinforce what I already know, get
> some new ideas and learn some new techniques.
>
> I had a problem with one of the code samples in the book because
> $this->_db->lastInsertId() was returning false even though the db insert was
> working as intended and the MySQL DB table being updated.
>
> In the book the author uses:
>
> // -------------
> // create a new row and set the fields/values
> // --------------
>
> // save the new row
> $row->save();
> // get last insert id
> $id = $this->_db->lastInsertId();
> // return the id
> return $id
>
> For me this just wasn't working. I do know, however that
> Zend_Db_Table_Row_Abstract::Save() returns the primary key when it is
> called. So I changed the code above to:
>
> // save new row
> $id = $row->save();
> // return the id
> return $id
>
> This then worked for me. What I wanted to ask is if anyone could tell me why
> the lastInsertId() method wasn't working in the first place? Thanks in
> advance,
>
> Matt
>
> --
> View this message in context:
> http://n4.nabble.com/lastInsertId-not-working-tp949153p949153.html
> Sent from the Zend DB mailing list archive at Nabble.com.
>
>


--
----------------------------------------
Pablo Morales
blog: http://blog.pablo-morales.com
linkedln: http://www.linkedin.com/pub/9/528/21
skype: pablofmorales
gtalk: pablofmorales@gmail.com
msn: pfm_mc@hotmail.com

没有评论: