I want to insert records into multiple tables at one go, I am doing this in the following way, is this the correct way of doing? If not, what is the better way? mysql_query("insert into table1 values('abc')"); mysql_query("insert into table2 values('ttt')"); mysql_query("insert into table3 values('5t6')"); mysql_query("insert into table4 values('ghy')"); mysql_query("insert into table5 values('gfd')"); Code (markup): Please help Thanx
Depending on your version, you may also be able to do: mysql_query("insert into table1 values('abc');insert into table2 values('ttt');insert into table3 values('5t6');insert into table4 values('ghy');insert into table5 values('gfd')"); PHP: Also if you can use the mysqli class, you can run a bunch of inserts as a single transaction: $db->autocommit(FALSE); $db->query("INSERT INTO table VALUES (blah, blah, blah)"); $db->query("INSERT INTO table VALUES (blah, blah, blah)"); $db->query("INSERT INTO table VALUES (blah, blah, blah)"); $db->query("INSERT INTO table VALUES (blah, blah, blah)"); $db->query("INSERT INTO table VALUES (blah, blah, blah)"); $db->query("INSERT INTO table VALUES (blah, blah, blah)"); $db->commit(); PHP:
I do it that way. However if these inserts will be done very often then you might have to look into different ways because it could slow down the server.