neutron has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone,

I'm having a little trouble getting started with dbi and mysql. I was just reviewing the tutorial:

http://www.perlmonks.com/?node_id=279077

It says I need the following:
- DBI
- Class::DBI and its related modules
- A relational database, MySQL is used for these examples, but could be modified for others
- The DBD for your database ( DBD::msql )

I'm using active state and the ppm. I can't seem to find the above modules in the list. There's about a million other packages related to them, e.g. DBIx-Array, DBIx-CGI, ... but no DBI and so on.

Help much appreciated!

Replies are listed 'Best First'.
Re: Setting up the dbi modules
by marto (Cardinal) on May 30, 2009 at 08:17 UTC

    Hi neutron,

    Take a look at A guide to installing modules for Win32 from the tutorials section of this site. Pay special attention to the section on repositories and using PPM::Repositorie add all known repositories to your PPM.

    Alternatively use the following syntax from the command line:

    c:\ppm install http://theoryx5.uwinnipeg.ca/ppms/DBI.ppd c:\ppm install http://theoryx5.uwinnipeg.ca/ppms/Class-DBI.ppd c:\ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppd

    However I think adding the repositories to ppm may be the best solution in the long run. Note the above packages are for Perl 5.8.8/ActivePerl 8xx.

    Update: Added last sentence.

    Hope this helps

    Martin

      Hi Martin,

      Thanks for the reply, this is exactly inline with what I am looking for. I just tried using the command line but it doesn't seem to work for me.

      I tried the following:
      c:\>ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/package.ppd
      And got the following:
      ppm install failed: No PPd found at http://cpan.uwinnipeg.ca/PPMPackag +e.ppd
      I also added trouchelle.com and cpan.uwinnipeg.ca to my repository and still no luck. I'm very confused :(

        I'm not sure if those are the URL you are actually trying, perhaps the uwinnipeg repository does not have 5.10 packages for the modules you are looking for. Try:

        ppm install http://trouchelle.com/ppm10/DBI.ppd

        Have you tried searching for these modules with ppm?

        Martin

Re: Setting up the dbi modules
by hda (Chaplain) on May 30, 2009 at 08:05 UTC
    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!

      hda, thanks for your reply. This looks pretty helpful. I'll give it a shot and see what happens!