Php/mysql multiple insert

software development

#1

I’m trying to do a multiple insert (several lines) to a mysql database table directly from php with the mysql_query command. I can enter one record but mysql won’t let me do anymore. For a long and convoluted reason, I can’t use phpmyadmin in this case. I’ve tried various combinations of queries with no success. Anyone have any success with this? I could always kludge it as a loop but the mysql/php documentation insists that I should be able to do a multiple insert with a single command.


#2

See http://www.burfield.com/blog/archives/000228.html

In case you’re not familar .= takes what is in a variable and appends to it. Then use your ordinary code to execute the query in the variable.

The article is a rant against Microsoft, but demonstrates it in MySQL. I have not personally tested the code, but the writer is a great programmer and it’s likely correct.

If the code errors, let me know the precise error reported.

Jim


#3

Jim,
Many thanks. Actually concantenation is unnecessary. It would help if I got more sleep. Somewhere in condensing the query from the mysql export I failed to replace the semi-colons after the INSERT INTO commands with commas. But reading your article tipped me off to my error. I’d tried just about every permutation but failed to notice my omission.

OTOH
going from
INSERT INTO etc. VALUES (etc);
INSERT INTO etc. VALUES (etc);
to this
INSERT INTO etc. VALUES (etc), (etc2), (etc3);
I left out the commas.