| Index
» Projects
» phpMyEdit
» Forum
» Getting last insert id? |
 |
vlad88sv
Joined: 25 Jan 2010
Posts: 3
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
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)
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
|
|
|
|