[Question][Mysql] I want to know... [Mysql][Question]

I want to know if we can insert data in several table with the same ID???

Thanks!

the answer is yes

But I don’t really understand … For example, someone register on my site (it will create a row in table ‘user’) but some information will be entered in table ‘user_info’, but there are also table that will be automatically opens like the table ‘money’. The user who have an id 1 in ‘user’ must have in table ‘user_info’ row with id 1 and also in table ‘money’. But if many people are register in the same time, what could happen??? the information will be mixed???

what should happen is that your application code will use the LAST_INSERT_ID function

check da manual

The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.

This means that if AUTO_INCREMENT, to a client, gave the ID 132 in the table ‘user’, AUTO_INCREMENT will give the same ID in the two other tables(‘user_info’ and ‘money’)??

no, you would retrieve the appropriate value using LAST_INSERT_ID – the other tables should not have an auto_increment column

Could you do an example with that code and LAST_INSERT_ID please…

     $dnn3 = $bdd->prepare('INSERT INTO user(firstname, lastname, username, password, email, regdate) VALUES (?, ?, ?, ?, ?, NOW())');
     $dnn3->execute(array($firstname, $lastname, $username, md5($password), $email));
     $dnn3->closeCursor();
     $dnn4 = $bdd->prepare('INSERT INTO user_info(birthdate) VALUES (?)');
     $dnn4->execute(array($birthday));
     $dnn4->closeCursor();

Where I should enter the LAST_INSERT_ID???

sorry, man, i don’t do perl or whatever that is

It php… You don’t know php???

that is correct sir, i don’t do php either

See: http://php.net/manual/en/function.mysql-insert-id.php

You have to execute that function after you have executed your insert query.