Garrett, Philip (MAN-Corporate) wrote:
> Corey wrote:
>> Greetings!
>> 
>> I'm using DBI w/ DBD::Pg, and am in the midst of attempting to
>> simplify some existing code. I happened on the following older
>> perl.com article: http://www.perl.com/pub/a/2001/03/dbiokay.html
>> which provides what seems to be a nicely concise way of constructing
>> INSERT statements: 
>> 
>>         @fields = qw( country firstname lastname );
>> 
>>         $fields = join(', ', @fields);
>> 
>>         $values = join(', ', map { $dbh->quote($_) }
>> @[EMAIL PROTECTED]);
> 
> You should use placeholders.  Here's how:
> 
>   @fields = qw( country firstname lastname );
> 
>   $sql = "INSERT INTO FOO ("
>        . join(",", @fields)
>        . ") VALUES ("
>        . join(",", ("?") x @fields) # a ? for each field
>        . ")";
> 
>   $dbh->do($sql, undef, @fields);

Doh!  That should be:

  $dbh->do($sql, undef, @[EMAIL PROTECTED]);

Regards,
Philip

Reply via email to