database= mysql language=php
I am coding program to work like this
PC1 =computer1
step
1.PC1 insert data ,new ID from Auto-increment.
2.PC1 select last ID
everything work fine but..
The problem when your code is used by many computers at the same mili-sec.
For example
- PC1insert data,Auto-increment new ID
2.PC2 insert data ,Auto-increment new ID
3.PC1 select last ID <——-Wrong
4PC2 select last ID
How to config database or modify php code to prevent this , thankyou.
You should use mysql_insert_id (or the equivalent call for the API you are using) to get the ID of the last inserted row.
I imagine that now you are doing this:
This won’t work unless you use transactions. But using the function
mysql_insert_idis the better way.In the documenation there is also a caution and some notes that you should read: