插入空行并获取最后一个id保存在php mysql中?

问题描述:

I have a registration form. If a user starts the form I insert a empty row in my mysql-table and get the last id like that:

$db=startConnection();
$query=" INSERT INTO form  VALUES ()";
$result=$db->query($query)
    or die($db->error);
$id=$db->insert_id;

But now I worry - isn't it possible that two users register at the same time and both get the same $id from the code above? For example, if two people hit the registration form at the same time and both "insert" queries are executed, and afterwards both people will get the same last insert_id?

PHP runs on the server and not on the clients side. Therefor once the first user submits the second submit will be executed after the first one has finise