MySQL LAST_INSERT_ID()和FOUND_ROWS() [英] MySQL LAST_INSERT_ID() and FOUND_ROWS()

查看:112
本文介绍了MySQL LAST_INSERT_ID()和FOUND_ROWS()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当PHP脚本每秒有数百个查询时,会发生什么情况?它会影响这些功能吗?是否可以保证它们将返回当前脚本中最后一个insert语句中最后一个插入的ID?它会返回当前脚本中最后一次选择的行数吗?如果同时有一个新的插入或选择(如果是FOUND_ROWS())怎么办?有问题吗?

What happens when there are hundreds of queries per second from PHP scripts? Does it affect these functions, is there a guarantee they will return the last inserted id from the last insert statement in the current script? Will it return the number of rows from the last select in the current script? What if there is a new insert or select (in case of FOUND_ROWS()) from another script at the same time? Is it an issue?

推荐答案

来自文档: 对于LAST_INSERT_ID(),将在每个连接的基础上将最新生成的ID保留在服务器中

From the docs: For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis

这意味着只要您不执行其他任何在连接上插入行的操作,该值就会保留下来以供您检索.

This means that at long as you don't execute anything else that inserts rows on your connection, the value is maintained for you to retrieve.

对于FOUND_ROWS: 通过FOUND_ROWS()可用的行计数是临时的,并且不能在SELECT SQL_CALC_FOUND_ROWS语句之后的语句之后可用.

For FOUND_ROWS: The row count available through FOUND_ROWS() is transient and not intended to be available past the statement following the SELECT SQL_CALC_FOUND_ROWS statement.

这意味着您必须在调用SQL_CALC_FOUND_ROWS之后立即执行它.这似乎也是连接范围的,但是文档中没有任何明确说明.

Which means that you must execute it immediately after your call to SQL_CALC_FOUND_ROWS. This appears to be connection-scoped as well, but nothing in the docs said that explicitly.

这篇关于MySQL LAST_INSERT_ID()和FOUND_ROWS()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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