Welcome to WebmasterWorld Guest from 126.96.36.199 , register , free tools , login , search , subscribe , help , library , announcements , recent posts , open posts Pubcon Platinum Sponsor
Running multiple INSERTS in same $sql Probably very simple.... ukgimp msg:1246063 10:07 am on Sep 13, 2002 (gmt 0) Hello
In an attempt to streamline some code (php) I would like to run multple insert commands. I have no problem getting the code to work if I call two separate SQL scripts eg.
$sql1 = "INSERT INTO tableX.....";
$pResult=mysql_query( $sql1 , $db_connection ); $sql2 = "INSERT INTO tableY....."; $pResult=mysql_query( $sql2 , $db_connection ); mysql_close($db_connection)
But when I try the following method it falls down. I get a parse error. Is there some reason why the following would not work.
$sql = "INSERT INTO tableX....;
INSERT INTO tableY...."; $pResult=mysql_query( $sql , $db_connection ); etc ect
The_Warden msg:1246064 2:05 pm on Sep 13, 2002 (gmt 0)
I believe the thing causing the problem is the semicolon (;) within $sql. PHP takes the semicolon as the closing statement. So to solve the problem I believe all you have to do is escape the semicolon (;). See below...
$sql = "INSERT INTO tableX....\;
INSERT INTO tableY....";