php - Insert values into two tables that are linked (1:M)
I have two tables user and email. One user can have multiple emails so its a seperate table(that contains user_id as part of its primary key). I would like to insert multiple attributes into user table and one email into email table as well. What is the best way to do that with mySQL query. Is there any single line command that will do that??
If i cant do that with just with mySql I can use php script as well
Update
I see that people are misunderstanding my question.
All i want to do is toinsert
values like username password into my user table and one email into the linked email table (the one linked to the same user)
I wonder what is the best way to do it in mySQL (and if necessarly Php)
I would like the answer to include the mySQL query (and php scrips as well if necessarily)
Answer
Solution:
The best way is to do it in a transaction. That way, if the e-mail insert fails the entire transaction will also fail.
Answer
Solution:
You should execute multiple SQL INSERT queries. I think the best way to do multiple operations monolite is to use SQL-transactions.
Answer
Solution:
You can do this;
Let me know if it works.
Answer
Solution:
Like this you can insert multiple values and multiple rows, but I never saw somehthing to do muliple insert into different tables.
The best thing to do is to insert a row into user retreive the user id with
mysql_insert_id
described here