Hi,

I might not be the ideal person to answer this, as I am not an expert in the field of databases. I have however some daily experience accessing PostgreSQL databases from Perl programs, so I hope this will help you.
To begin with, we will only use DBI and assume you already have a user and a password, to access some table in some database. Then we can define:

use DBI; my $database = 'databasename'; my $dbuser = 'username'; my $usrpsswd = 'password'; my $dbtable = 'tablename';


Then you need to define a database connection, and a query (here defined for PostgreSQL):

my $dbconnection = DBI->connect("dbi:Pg:dbname=$database", $dbuser, $u +srpsswd);


Then you will need to prepare an SQL query for your connection:
my $query = $dbconnection->prepare(<<End_SQL); SELECT something1,something2 FROM $dbtable End_SQL

Then execute:

$query->execute();


Then you can make, for example, a while loop to catch all the things you asked for in your query:

while (($something1,$something2) = $query->fetchrow_array() ) { do your stuff here } # and then disconnect $dbconnection->disconnect();


These very simple things work for me. Be careful that I have not mentioned anything on secure connections and other advanced stuff. Other monks might be able to help on that. My lines only refer to very simple and basic database access.

Hope this helps!


In reply to Re: Setting up the dbi modules by hda
in thread Setting up the dbi modules by neutron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.