amosjb — 2012-04-15T15:17:14-04:00 — #1
I want to know if we can insert data in several table with the same ID???????
r937 — 2012-04-15T16:36:06-04:00 — #2
amosjb — 2012-04-15T17:41:09-04:00 — #3
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???
r937 — 2012-04-15T18:41:56-04:00 — #4
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.
amosjb — 2012-04-15T18:58:40-04:00 — #5
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')??
r937 — 2012-04-15T19:03:03-04:00 — #6
no, you would retrieve the appropriate value using LAST_INSERT_ID -- the other tables should not have an auto_increment column
amosjb — 2012-04-15T19:12:43-04:00 — #7
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));
$dnn4 = $bdd->prepare('INSERT INTO user_info(birthdate) VALUES (?)');
Where I should enter the LAST_INSERT_ID???
r937 — 2012-04-15T19:49:58-04:00 — #8
sorry, man, i don't do perl or whatever that is
amosjb — 2012-04-15T20:32:18-04:00 — #9
It php.... You don't know php???
r937 — 2012-04-15T21:09:14-04:00 — #10
that is correct sir, i don't do php either
rvand85 — 2012-04-16T08:45:11-04:00 — #11
You have to execute that function after you have executed your insert query.