SQL query string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bluesman333
Forum Commoner
Posts: 52
Joined: Wed Dec 31, 2003 9:47 am

SQL query string

Post by bluesman333 »

How can I have, for example, multiple INSERT statements in a string and pass that string to
mysql_query?

$sql .= "INSERT INTO table (column1, column2) VALUES ('apple', 'orange')";
$sql .= "INSERT INTO table (column1, column2) VALUES ('red', 'blue')";

mysql_query($sql, $conn);

This is basically what I have but I'm geting an error.

I've also tried:
$sql .= "INSERT INTO table (column1, column2) VALUES ('apple', 'orange');";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_query() doesn't support multiple statements.. however you may be able to perform:

Code: Select all

INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
which would, provided your install supports it, create 2 records.
Post Reply