Re: [fw-general] Getting the id generated after insert
Hi, how about lastInsertId()? http://framework.zend.com/manual/en/zend.db.html $db-insert('bugs', $data); // return the last value generated by an auto-increment column $id = $db-lastInsertId(); -- Juozas Kaziukėnas (juo...@juokaz.com) Aš internete - JuoKaz (http://www.juokaz.com) On Sat, Jul 18, 2009 at 4:59 PM, debussy007 debussy...@gmail.com wrote: Hello, When I insert a record in a table like $db-insert('my_table', $data); I would like to get the new id generated. ($db is the Db Adapter) What is the best way to achieve this ? When I was using Zend_Db_Table_Abstract I just had to do return $myTable-insert ... and the insert method would return the new id. However the insert method of the Zend_Db_Adapter_Abstract won't return the new id but the number of rows affected (which will always be 1 I guess ...) -- View this message in context: http://www.nabble.com/Getting-the-id-generated-after-insert-tp24549260p24549260.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Getting the id generated after insert
Isn't it always 1? Is it possible to insert multiple rows at once? Regards, Saša Stamenković On Sat, Jul 18, 2009 at 6:05 PM, Juozas juo...@juokaz.com wrote: Hi, how about lastInsertId()? http://framework.zend.com/manual/en/zend.db.html $db-insert('bugs', $data); // return the last value generated by an auto-increment column $id = $db-lastInsertId(); -- Juozas Kaziukėnas (juo...@juokaz.com) Aš internete - JuoKaz (http://www.juokaz.com) On Sat, Jul 18, 2009 at 4:59 PM, debussy007 debussy...@gmail.com wrote: Hello, When I insert a record in a table like $db-insert('my_table', $data); I would like to get the new id generated. ($db is the Db Adapter) What is the best way to achieve this ? When I was using Zend_Db_Table_Abstract I just had to do return $myTable-insert ... and the insert method would return the new id. However the insert method of the Zend_Db_Adapter_Abstract won't return the new id but the number of rows affected (which will always be 1 I guess ...) -- View this message in context: http://www.nabble.com/Getting-the-id-generated-after-insert-tp24549260p24549260.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Getting the id generated after insert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 $id = $db-insert('my_table', $data); ... : ___ _ ___ ___ ___ _ ___: : | \ /_\ / __| _ \ _ (_) \ : : | |) / _ \\__ \ _/ / | |) | : : |___/_/:\_\___/_| |_|_\_|___/ : ::: : Web: http://www.dasprids.de : : E-mail : m...@dasprids.de : : Jabber : jab...@dasprids.de : : ICQ: 105677955 : ::: debussy007 schrieb: Hello, When I insert a record in a table like $db-insert('my_table', $data); I would like to get the new id generated. ($db is the Db Adapter) What is the best way to achieve this ? When I was using Zend_Db_Table_Abstract I just had to do return $myTable-insert ... and the insert method would return the new id. However the insert method of the Zend_Db_Adapter_Abstract won't return the new id but the number of rows affected (which will always be 1 I guess ...) -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpiNCsACgkQ0HfT5Ws789DdbACgjJUBZRdafwHoq5XIreIyR7H5 q3wAoKEg7RF0tiIuBP04VMRwZ6bqglN/ =rcYA -END PGP SIGNATURE-
Re: [fw-general] Getting the id generated after insert
Hey Dasprid, $id = $db-insert('my_table', $data); is incorrect. I need to use e.g.: $db-insert('my_table', $data); return $db-lastInsertId(); only the insert method of the Zend_Db_Table class will return the id, the one of the Zend_Db_Adapter will return the number of rows affected. Thanks all. (By the way, how is it possible to have more than 1 row affected when you use -insert(...) ?) DASPRiD wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 $id = $db-insert('my_table', $data); ... : ___ _ ___ ___ ___ _ ___: : | \ /_\ / __| _ \ _ (_) \ : : | |) / _ \\__ \ _/ / | |) | : : |___/_/:\_\___/_| |_|_\_|___/ : ::: : Web: http://www.dasprids.de : : E-mail : m...@dasprids.de : : Jabber : jab...@dasprids.de : : ICQ: 105677955 : ::: debussy007 schrieb: Hello, When I insert a record in a table like $db-insert('my_table', $data); I would like to get the new id generated. ($db is the Db Adapter) What is the best way to achieve this ? When I was using Zend_Db_Table_Abstract I just had to do return $myTable-insert ... and the insert method would return the new id. However the insert method of the Zend_Db_Adapter_Abstract won't return the new id but the number of rows affected (which will always be 1 I guess ...) -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpiNCsACgkQ0HfT5Ws789DdbACgjJUBZRdafwHoq5XIreIyR7H5 q3wAoKEg7RF0tiIuBP04VMRwZ6bqglN/ =rcYA -END PGP SIGNATURE- -- View this message in context: http://www.nabble.com/Getting-the-id-generated-after-insert-tp24549260p24552365.html Sent from the Zend Framework mailing list archive at Nabble.com.