mysql_insert_id 使用安全吗? [英] Is mysql_insert_id safe to use?

查看:27
本文介绍了mysql_insert_id 使用安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 PHP 文档,mysql_insert_id 从 mysql 表中获取最后插入的 id.

According to the PHP documentation, mysql_insert_id takes the last inserted id from the mysql table.

我的问题是,如果我有一个网站每秒向数据库插入超过 2 行,我是否可以使用 mysql_insert_id 并获得我在 中所指的正确 IDINSERT 查询前一行?

My question is, if I have a website that inserts more than 2 rows per second to the DB, can I use the mysql_insert_id and get the correct ID I am referring to in the INSERT query a line before?

推荐答案

来自 MySQL 手册:

From the MySQL manual:

生成的 ID 以每个连接为基础在服务器中维护.这意味着函数返回给给定客户端的值是为该客户端影响 AUTO_INCREMENT 列的最新语句生成的第一个 AUTO_INCREMENT 值.此值不会受到其他客户端的影响,即使它们生成自己的 AUTO_INCREMENT 值.此行为可确保每个客户端都可以检索自己的 ID,而无需担心其他客户端的活动,也无需锁定或事务.

The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.

简短版本:使用安全.

这篇关于mysql_insert_id 使用安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆