|
Posted by Connector5 on 12/21/05 18:07
Warning when pulling last_insert_ids:
In a high-traffic server, last_insert_id could actually return a false
result if two records are inserted at near the same time. Since queries are
queued in order of request, you will definitely get overlap some day.
Please take the time to lock your tables when pulling the last insert id and
DONT FORGET TO UNLOCK THEM. They should be locked for the shortest time
possible. Here is a mysql example:
mysql_query("LOCK TABLES $table WRITE");
mysql_query("SET AUTOCOMMIT = 0");
mysql_query("insert into $table ($keys) values ($vals)");
if (mysql_affected_rows())
{
$last_id = mysql_insert_id();
}
else
{
$last_id = -1;
}
mysql_query("COMMIT");
mysql_query("SET AUTOCOMMIT = 1");
mysql_query("UNLOCK TABLES");
This wont provide a solution to your problem, but I hope you find this
useful. I once had a beautiful web application that set your session_id
from the last_insert_id. It worked solidly in design with only 5 of us
playing with it, but when 5000 people got ahold of it, we had some unwanted
spoofing.
"Ashok" <none@mail.com> wrote in message
news:doacbv$2fb5$1@gavrilo.mtu.ru...
> How to make a statement where I have to query db and select all from table
> where id = last insert id? I have to use the rows info to redirect to page
> with this info.
> Something like $query_rsRedirect = "SELECT * FROM table WHERE id =
> LAST_INSERT_ID()";
> and redirectpage will be
> subcat.php?catid={rsRedirect.catid}&subcatid={rsRedirect.subcatid}
>
> It shows a blank page, although data is inserted.
>
> Ashok.
>
>
Navigation:
[Reply to this message]
|