Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Getting last insert id?

phpMyEdit General     Getting last insert id?
Odoslať novú tému   Odpovedať na tému    
 
vlad88sv     Založený: 25.01.2010   Príspevky: 3  
Príspevok Zaslal: 2010-01-25 18:08
Návrat hore  Odpovedať s citátom     

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     Založený: 25.01.2010   Príspevky: 3  
Príspevok Zaslal: 2010-01-25 19:46
Návrat hore  Odpovedať s citátom     

...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     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2010-02-27 04:05
Návrat hore  Odpovedať s citátom     

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.

Kód:
if($last_insert_id = @mysql_insert_id($this->dbh)){

   // header

}else{

   die('Insert failed');

}


 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov