Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

using databases

by Bass-Fighter (Beadle)
on Jan 06, 2009 at 09:26 UTC ( [id://734379]=perlquestion: print w/replies, xml ) Need Help??

Bass-Fighter has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, I have a question.

I am busy with a program in perl, and now I want to get my variables into a database with postgreSQL. I already have read the modules on cpan, but I don't understand it at all... so is there anyone who know's a site where those pieces of code are used in a program in perl? maybe I understand it if I see how to use the modules

with kind regards, Bass-Fighter

Replies are listed 'Best First'.
Re: using databases
by Seqi (Acolyte) on Jan 06, 2009 at 09:49 UTC
    http://linuxbloggers.org/create-insert-select-update-perl-script-and-postgresql-database-examples/
    ^ will probably be enough but a nifty thing I 'borrowed' from a site I haven't bookmarked anywhere:
    ############ # Update the database # @param1: the table to be updated # @param2: the hash containing the data to be inserted into the databa +se # returns 1 if succesfull ############ sub updateDB { my $table = shift; my ($hashref) = @_; my (%hash) = %$hashref; my @fields; @fields = keys %hash; my $fields = join(', ', @fields); my $values = join(', ', map { $dbh->quote($_) } @hash{@fields}); my $sql = "INSERT into $table ($fields) values ($values)"; my $sth = $dbh->prepare($sql); $sth->execute(); $sth->finish(); return 1; }
    You'll want the keys of the hash to be the names of the colums you want to insert
      ok thanks, I think this is what I was looking.
Re: using databases
by eighty-one (Curate) on Jan 06, 2009 at 14:14 UTC
      thanks to you too, it is very usefull

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found