2

我们知道 mysql_insert_id() 将给出最后插入的 ID,但我想知道在下面的情况下我们是否会遇到问题。


UserA -> 调用将插入 ROW 到 TABLE 并获取插入的 ID 的函数

执行日期时间:2013-10-01 10:18:25

行号:1


UserB -> 调用将插入 ROW 到 TABLE 并获取插入的 ID 的函数

执行日期时间:2013-10-01 10:18:26

行号:2


请注意,执行时间仅相差一秒。

假设 UserB 在 UserA 执行 mysql_insert_id() 之前完成插入行

UserA 是否会获得ROW ID: 1ROW ID: 2的值

4

3 回答 3

5

No.mysql_insert_id()也是连接安全的,因此对于每个用户,它将包含正确的数据,因为他们将使用不同的连接。

请注意,使用mysql_是个坏主意,因为它们已被弃用

于 2013-10-01T13:21:48.030 回答
3

两个用户将拥有不同的 MySQL 资源链接。PHP 通过将$link_identifier参数作为可选参数来为您执行此操作,但您应该指定它。

见: http: //php.net/manual/en/function.mysql-insert-id.php

强制:不要使用mysql_*函数,它们已被弃用。

于 2013-10-01T13:21:05.910 回答
0

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.

于 2013-10-01T13:25:05.873 回答