Re: Get the last insert id
Thanks guys! I used your advice running a query on the latest ID. I dont have to worry about a race condition so it works great, thanks! -- View this message in context: http://cakephp.1045679.n5.nabble.com/Get-the-last-insert-id-tp3236536p3252664.html Sent from the CakePHP mailing list archive at Nabble.com. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
What if I made the insert 20 days ago, how could I get the last id? I want to get the current ID value in the beforeSave function to apend it to a file I'm saving... Any thouhts? kevando On Oct 25, 11:17 pm, Larry E. Masters php...@gmail.com wrote: $this-Model-save(); $id = $this-Model-id; -- Larry E. Masters On Mon, Oct 25, 2010 at 11:14 PM, cricket zijn.digi...@gmail.com wrote: On Mon, Oct 25, 2010 at 11:51 PM, Robert J. Maiolo rmai...@gmail.com wrote: after your save statement.. $var = $this-Contact-lastInsertId(); It's getInsertID(). You're probably thinking of getLastInsertID(), which has been deprecated. Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.c omFor more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
On Wed, November 3, 2010 7:05 pm, kevando wrote: What about if my last insert/save was 20 days ago? Basically -- I want to get the value of the current (or latest) id in the beforeSave function $this-Model-getLastInsertId(); http://book.cakephp.org/view/312/Models does what it says on the can. thanks, Kev -- View this message in context: http://cakephp.1045679.n5.nabble.com/Get-the-last-insert-id-tp3236536p3248988.html Sent from the CakePHP mailing list archive at Nabble.com. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -- Mike Karthauser Managing Director - Brightstorm Ltd Email: mi...@brightstorm.co.uk Web: http://www.brightstorm.co.uk Tel: 07939 252144 (mobile) Fax: 0870 1320560 Address: 1 Brewery Court, North Street, Bristol, BS3 1JS Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
On Nov 4, 3:50 pm, Mike Karthauser mi...@brightstorm.co.uk wrote: On Wed, November 3, 2010 7:05 pm, kevando wrote: What about if my last insert/save was 20 days ago? why don't you insert and then update if you want to do that. you can easily wrap that in a transaction. anything else you do just risks a race condition. Basically -- I want to get the value of the current (or latest) id in the beforeSave function $this-Model-getLastInsertId(); http://book.cakephp.org/view/312/Models does what it says on the can. which is return null unless you just inserted something. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
you could use find-first() with order: id=DESC this would get you the last insert id, no matter how many days passed although the above race conditions might result in problems (depending on the usage of this id) On 4 Nov., 16:28, AD7six andydawso...@gmail.com wrote: On Nov 4, 3:50 pm, Mike Karthauser mi...@brightstorm.co.uk wrote: On Wed, November 3, 2010 7:05 pm, kevando wrote: What about if my last insert/save was 20 days ago? why don't you insert and then update if you want to do that. you can easily wrap that in a transaction. anything else you do just risks a race condition. Basically -- I want to get the value of the current (or latest) id in the beforeSave function $this-Model-getLastInsertId(); http://book.cakephp.org/view/312/Models does what it says on the can. which is return null unless you just inserted something. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
@Kevando - If you want the ID of something that happened 20 days ago, you cant get the last insert ID. That only applies when you literally just ran a query and need to get the ID. If you want it from 20 days ago, do a find query and order by DESC limit 1. On Nov 4, 8:36 am, euromark dereurom...@googlemail.com wrote: you could use find-first() with order: id=DESC this would get you the last insert id, no matter how many days passed although the above race conditions might result in problems (depending on the usage of this id) On 4 Nov., 16:28, AD7six andydawso...@gmail.com wrote: On Nov 4, 3:50 pm, Mike Karthauser mi...@brightstorm.co.uk wrote: On Wed, November 3, 2010 7:05 pm, kevando wrote: What about if my last insert/save was 20 days ago? why don't you insert and then update if you want to do that. you can easily wrap that in a transaction. anything else you do just risks a race condition. Basically -- I want to get the value of the current (or latest) id in the beforeSave function $this-Model-getLastInsertId(); http://book.cakephp.org/view/312/Models does what it says on the can. which is return null unless you just inserted something. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Get the last insert id
Hello I am using cakePHP 1.3 and I am unable to retreive the last inserted row's id. I actually am using $this-Model-id to retreive the last inserted id but I am unable to get the id. When tried to check what is return type, it says as bool(false), which means nothing is returned. Here I am loading a different model in a different controller, so would that be the issue?? But even though I am loading, I get back nothing!! $this-loadModel('Contact'); $this-Contact-query(insert into contacts(tblContact_firstName,tblContact_lastName,tblContact_company,tblContact_department,tblContact_address,tblContact_country,tblContact_city,tblContact_state,tblContact_zipcode,tblContact_phone1,tblContact_email1) values('$sanitizedFormData[fname]','$sanitizedFormData[lname]','','$sanitizedFormData[company]','$sanitizedFormData[address]','$sanitizedFormData[country]','$sanitizedFormData[city]','$sanitizedFormData[state]','$sanitizedFormData[zip]','$sanitizedFormData[phone]','$sanitizedFormData[email]');); $this-loadModel('Contact'); $contactId = $this-Contact-id; And when I printed the $this-Contact array recursively, I found the value of id key empty. So that explains why I was receiving an empty value. Now given my situation, how would I get the last inserted id, specific to the controller Contact?? Is it possible? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
after your save statement.. $var = $this-Contact-lastInsertId(); On Mon, Oct 25, 2010 at 7:48 AM, macha srin...@gmail.com wrote: Hello I am using cakePHP 1.3 and I am unable to retreive the last inserted row's id. I actually am using $this-Model-id to retreive the last inserted id but I am unable to get the id. When tried to check what is return type, it says as bool(false), which means nothing is returned. Here I am loading a different model in a different controller, so would that be the issue?? But even though I am loading, I get back nothing!! $this-loadModel('Contact'); $this-Contact-query(insert into contacts(tblContact_firstName,tblContact_lastName,tblContact_company,tblContact_department,tblContact_address,tblContact_country,tblContact_city,tblContact_state,tblContact_zipcode,tblContact_phone1,tblContact_email1) values('$sanitizedFormData[fname]','$sanitizedFormData[lname]','','$sanitizedFormData[company]','$sanitizedFormData[address]','$sanitizedFormData[country]','$sanitizedFormData[city]','$sanitizedFormData[state]','$sanitizedFormData[zip]','$sanitizedFormData[phone]','$sanitizedFormData[email]');); $this-loadModel('Contact'); $contactId = $this-Contact-id; And when I printed the $this-Contact array recursively, I found the value of id key empty. So that explains why I was receiving an empty value. Now given my situation, how would I get the last inserted id, specific to the controller Contact?? Is it possible? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
On Mon, Oct 25, 2010 at 11:51 PM, Robert J. Maiolo rmai...@gmail.com wrote: after your save statement.. $var = $this-Contact-lastInsertId(); It's getInsertID(). You're probably thinking of getLastInsertID(), which has been deprecated. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Get the last insert id
$this-Model-save(); $id = $this-Model-id; -- Larry E. Masters On Mon, Oct 25, 2010 at 11:14 PM, cricket zijn.digi...@gmail.com wrote: On Mon, Oct 25, 2010 at 11:51 PM, Robert J. Maiolo rmai...@gmail.com wrote: after your save statement.. $var = $this-Contact-lastInsertId(); It's getInsertID(). You're probably thinking of getLastInsertID(), which has been deprecated. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en