0

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')");

Please help


Thanx

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by rajarajan07
0

Yep. This is correct. But, its a good practice to have column name in your insert query. And also, Dont execute your query directly. Store the query in a variable and then execute it. This way, if you encounter any problem, you can easily print the query for manual testing.
ie.,

$query = "insert into table1 (col1) values ('ttt')";
mysql_query($query);

Cheers,
Naveen

0

i think better be like this :

$query = "INSERT INTO table1 (col1)
          VALUES
          ('abc'),('ttt'), ('5t6'), ('gfd')";
mysql_query ($query,$connction);
0

Considered all tables are in a single database:

$query = "insert into table1 (col1) values ('data')";
mysql_query($query);
$query = "insert into table2 (col1) values ('data')";
mysql_query($query);
$query = "insert into table3 (col1) values ('data')";
mysql_query($query);
$query = "insert into table4 (col1) values ('data')";
mysql_query($query);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.