pdo multi-insert problem

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
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

pdo multi-insert problem

Post by kc11 »

Hi everyone,

I am struggling to perform the following mysql multiple insert using pdo.

Here is the php code:

Code: Select all

   $sql="INSERT INTO milp(`<!--#echo var="auth_type" -->` , `<!--#echo var="content_length" -->`) VALUES 

((none1,none2) , (none3,none4)) "


 $dbh->exec($sql);
    $dbh=null;



[text]

INSERT INTO milp(`<!--#echo var="auth_type" -->` , `<!--#echo var="content_length" -->`) VALUES ((none1,none2) , (none3,none4)).
[/text]

when I test the above sql string with phpmyadmin I get the following output:

#1054 - Unknown column '<!--#echo var="auth_type" -->' in 'field list'

INSERT INTO milp( `<!--#echo var="auth_type" -->` , `<!--#echo var="content_length" -->` )
VALUES (
none1, none2
), (
none3, none4
)
using showtable create , I get ( in part ):

`milp` (
` 1` char(40) DEFAULT NULL,
` <!--#echo var="auth_type" -->` char(40) DEFAULT NULL,
` <!--#echo var="content_length" -->` char(40) DEFAULT NULL,

Can anyone explain this?

Thank you,

KC
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: pdo multi-insert problem

Post by twinedev »

Well if you are copying and pasting directly, other than the first field in the table, you have a space in front of each field name.

My personal question would be, why the heck would you have field names like that? LOL

-Greg
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

Re: pdo multi-insert problem

Post by kc11 »

Greg,

Thank you. I was able to fix the field names after your comment. I have to remember that in SQL, the whitespace counts.

BTW, the field names are related to server variables. I could have made them more readable, but as as an experiment, since I am inexperienced with mysql, I wanted to try and use the more complex field names.

Thanks again,

KC
Post Reply