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.
没有评论:
发表评论