请转到本页的评论部分。
http://php.net/manual/en/function.mysql-insert-id.php
你应该看到一些可能适合你的方法。
我会尝试插入特定的time_stamp,然后再次调用time_stamp insert。
戴夫在这篇评论中做了很好的解释。引用他..
There is a lot of incorrect info here on "don't use AI" and "using max
is equivalent". Then you have people improperly advising you to use
psuedo-random numbers
If you're really worried about the AI field not returning because of
the inherent race conditions, just do a select statement based on the
vars you just input. If your vars are not unique, DON'T use these
psuedo-random numbers. When you have enough iterations, the
probability that the one of these randoms becomes a duplicate gets
pretty high.
Instead, just use the unix timestamp. However, don't use
UNIX_TIMESTAMP() in your query, because if you do, when you run your
select statement right after, there's a possibility that you'll end up
with a different timestamp.
Since date() continues to count up during the execution of the script,
simply store date(U) into a variable or definition. Then insert and
select based on that. Assuming you're not using mysql procedures:
define(UNIX_TIMESTAMP, date('U'));
$db->query("insert into table values('', 'a', 'b', 'c', 'd', '".UNIX_TIMESTAMP."'");
$res = $db->query("select id from table where a_col = 'a' and b_col = 'b' and c_col = 'c' and d_col = 'd' and temp_id = 'UNIX_TIMESTAMP'");
//...
?>