PDA

View Full Version : multiple inserts as string


Ökii
04-29-2003, 01:16 PM
txt file upload, parsing that to get some values and inserting into database - simple enough.

to avoid looping and therefore multiple queries, I wanted to build a string and just put that into the mysql_query call ---

for( --- loop -- )
{
$query_string .= "INSERT INTO `a` VALUES('$b','$c'); ";
}
$addem = mysql_query($query_string);

which manages to insert the first one and then returns an error for the second.

If I echo the string and put it into a phpmyadmin sql query box it works fine, updates however many rows are read from the file.

Any idea what is wrong with the string building for a php+mysql query? Is it ok to seperate inserts with ; ?

mordred
05-02-2003, 12:06 AM
mysql_query() lets you only issue one query statement, multiple queries fail. It is just how this function works.

phpMyAdmin makes exactly what you don't wanted to do: It splits the queries text into separate queries and invokes mysql_query() for each query. Looks like magic from the outside, but there is no real trick here.

Ökii
05-02-2003, 09:52 PM
cheers mord - thought I'd speed up the update somewhat (maybe should listen to Einstein and accept that lightming only goes so fast)