Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: DBI Insert not working

by wind (Priest)
on Jun 10, 2011 at 02:00 UTC ( [id://909029]=note: print w/replies, xml ) Need Help??


in reply to DBI Insert not working

This does not directly relate to your issue. However, whenever I have a query like that, I often prefer to build the sql statement instead of having a chain of placeholders that might or might not be balanced with the correct field.

To ensure better readability and quality assurance, I simply create an intermediate data structure that is transformed into the fields and values like so:

my @pairs = ( name => $name, country => $country, language => $language, union => $union, title => $title, email => $email, cellphone => $cellphone, landlinephone => $landlinephone, facebook => $facebook, skype => $skype, twitter => $twitter, gender => $gender, age => $age, needshelp => $needshelp, ); my @fields = do {my $b = 0; grep {$b ^= 1} @pairs}; my @values = do {my $b = 1; grep {$b ^= 1} @pairs}; $sth = $dbh->prepare('INSERT INTO istanbul2011 SET ' . join ',', map { +"$_=?"} @fields)); $sth->execute(@values) or die $dbh->errstr

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://909029]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-28 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found