| Index
» Projekty
» phpMyEdit
» Fórum
» Getting last insert id? |
 |
vlad88sv
Založený: 25.01.2010
Príspevky: 3
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
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)
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
|
|
|
|