To get the next auto_increment id you can use:
SELECT auto_increment FROM information_schema.tables WHERE table_name = 'table-you-want-to-check';
However, you may not want to rely on the auto_increment
id or last_insert_id()
in your code's logic. For example, let's say two people, A & B, are adding questions to your db at close to the same moment and you're using the last_insert_id()
to determine the id of the person's question. What happens when they both submit their question at the same time? Is the last_insert_id()
from person A or B?
One method to overcome this issue is to use a "pre-defined" id or guid in addition to or in place of the auto incremented id.