I am setting up an event in php, and saving it to mysql. Later, I want to update the event, but in order to know which event needs to be updated, I use the time it was created.
However if several events start at the exact same second I might run into problems down the line if we have many users. My solution is to check for starttime and usernumber, which I believe should be unique enough. Is this okay? is there a better way to do it?
First, when creating the event:
$starttime = time();
mysql_query("INSERT INTO events (userid, starttime)
VALUES ('$userid', '$starttime')");
Later, updating the event:
mysql_query("UPDATE events
SET newdata='$newdata'
WHERE starttime='$starttime'
AND userid='$userid'");
Bad bad way to go. Just put an auto_incrementing primary key ID field on that table, which will give you a guaranteed unique non-repeat value you can UNIQUELY identify a row with without any fear of overlaps/conflicts:
You can retrieve that value automatically after an insert query: