After I use the function '->lastInsertId()' to retrieve the lat ID of the table I recieve back '0'. I can not discover the solution. My table is definitely an autoincrement
I attempt to have it within the controller with this particular code.
$reviews = new Application_Model_DbTable_Reviews(); $lastId = $reviews->getAdapter()->lastInsertId(); echo $lastId;
I really hope someone might help me.
Well these things are not mention in paperwork however it works best for e.g for those who have table title 'Book' with PK book_id , FK user_id and 'User' table with PK user_id
<<Book>> *book_id title user_id <<User>> *user_id name age
$userTb = new Model_DbTable_User(); $user = $userTb->createRow(); $user->name = "jason"; $user->age = 25; $user->save();
//well after saving the record ZF populates PK for you personally so now you must read only use of auto incremented PK by simply $userTb->user_id
$bookTb = new Model_DbTable_Book(); $book = $bookTb->createRow(); $book->title = 'php'; $book->user_id = $user->user_id; $bookId = $book->save(); // this is another way of accessing auto generated PK at insert tim .