Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Perl Access Database

by fs (Monk)
on May 22, 2001 at 20:39 UTC ( [id://82283]=note: print w/replies, xml ) Need Help??


in reply to Perl Access Database

For this type of scenario, I usually store individual column names and values in a pair of arrays and join them, something like this
if(is_valid($form{'field1'})){ push(@fields, 'field1'); push(@values, $form{'field1'}); } if(is_valid($form{'field2'})){ push(@fields, 'field2'); push(@values, $form{'field2'}); } # repeat, with appropriate validity tests, for # each field/column $query = $dbh->prepare("insert into table (" . join(',',@fields) . ") values (" . join(',', @values) . ")"); $query->execute;

Replies are listed 'Best First'.
Re: Re: Perl Access Database
by Spudnuts (Pilgrim) on May 23, 2001 at 00:55 UTC
    Prepared DBI queries are even nicer--you don't have to worry about doing the escaping of the values. Just use a ? for each value in @values in the SQL statement and then pass @values into $query->execute().

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found