2009年12月5日星期六

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

Out of curiosity, what is the return value of the $row->save()
operation? This SHOULD be the primary key of the row that oyu just
returned. Also, is this mysqli or pdo/mysql?

-ralph

waldenguy wrote:
> Yeah, this is the exported SQL for my pages table:
>
> CREATE TABLE IF NOT EXISTS `pages` (
> `id` int(11) NOT NULL AUTO_INCREMENT,
> `parent_id` int(11) DEFAULT NULL,
> `namespace` varchar(50) DEFAULT NULL,
> `name` varchar(100) DEFAULT NULL,
> `date_created` int(11) DEFAULT NULL,
> PRIMARY KEY (`id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
>
>
>
> pablofmorales wrote:
>> 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
>>
>>
>

没有评论: