I have a database which is frequently updated by the main script which is php encrypted and i can’t read or edit it
I need to have another script separately which can also add a row at the end of the table with a new ID and it shouldn’t duplicate with id’s created by the main script, (the other script could have been updated within or a few seconds after that i’ve read ID)
So, How can i read the latest ID column value, and then create a new row for this purpose?
it doesn’t matter if in my new script, ID# is increased with +2 or even +5, because the main script always reads the last ID and makes it +1
i just don’t one them to make the same ID at the same time
You don’t need any trickery here, just set the ID column to be
PRIMARYandAUTO_INCREMENT, this will mean MySQL will assign the next available int to your row, and allow the old script to insert whatever it wants, avoiding collisions.More info on that here: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html