Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Wednesday, November 11, 2026
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  phpMyEdit  »  Forum  »  Getting last insert id?

phpMyEdit General     Getting last insert id?
Post new topic   Reply to topic    
 
vlad88sv     Joined: 25 Jan 2010   Posts: 3  
Post Posted: 2010-01-25 18:08
Back to top  Reply with quote     

Hi!, I would like to send a Location header after an insertion, but I need to get the last insert id in order to generate the URL which I'm going to redirect the user to.

Is this possible with current phpMyEdit?.

 
vlad88sv     Joined: 25 Jan 2010   Posts: 3  
Post Posted: 2010-01-25 19:46
Back to top  Reply with quote     

...right now I'm selecting the MAX(id) -- id = autonumeric primary key -- after calling new phpMyEdit($opts) but I guess it may produce a race condition if concurrency is too high, very hard to happen but there's the possibility.

 
doug     Joined: 10 Feb 2003   Posts: 1013   Location: Denver, Colorado (USA)
Post Posted: 2010-02-27 04:05
Back to top  Reply with quote     

MAX(id) is probably as good a method as any. In the unlikely event the insert fails, a trigger with the following may be slightly better.

Code:
if($last_insert_id = @mysql_insert_id($this->dbh)){

   // header

}else{

   die('Insert failed');

}


 
Post new topic   Reply to topic    

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Application form
Report bug on PLATON.SK website · Terms of use · Privacy policy