Page 1 of 1

SQL query string

Posted: Thu Aug 18, 2005 11:25 pm
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');";

Posted: Thu Aug 18, 2005 11:38 pm
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.