MySQL LAST_INSERT_ID() and 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?
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.
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.
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.
精彩评论