in reply to Inserting into mysql and getting inserted id at the same time
The SQL server will always serialize the incoming requests – they never literally occur "at the same time." Follow the advice already given to create a statement handle and retrieve the id. Also: if you need to perform a series of SQL statements without the possibility of interference, use explicit SQL "transactions." You begin the transaction, issue your statements, then "commit" to cause all of them to take effect at once.