Page 1 of 1

pdo multi-insert problem

Posted: Sat Jul 16, 2011 10:35 pm
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

Re: pdo multi-insert problem

Posted: Sun Jul 17, 2011 2:24 am
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

Re: pdo multi-insert problem

Posted: Mon Jul 18, 2011 6:32 am
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