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

This has been reformatted for easier use!

Hello all,
I have some PostgreSQL/Perl problems.
I am using RedHat Linux 7.0 with Apache.

I wrote a test script to see if I could connect to my local
Postgres database but it didn't work. When I looked at the
error log it said

"DBI.pm" cannot be found

referring to "use DBI;" in my code.
I was under the impression that Perl had native support for
Postgres so I tried connecting without use DBI; using:

$dbh = DBI->connect("dbi:Pg:dbname=name","user","password");

but an error was caused and the error log said:

Cannot find method "connect" in module "DBI"

Does this mean that Perl has native support for Postgres
but I'm using the wrong method to connect?
If not, do I need to install DBI.pm? Where do I install it?

Any help would be greatly appreciated.
D.

Replies are listed 'Best First'.
Re: PostgreSQL/Perl help Reformatted
by kwoff (Friar) on Nov 01, 2001 at 23:05 UTC
    Perl doesn't have "native" support for PostgreSQL. It doesn't even have DBI stuff natively. You use DBI, which is a library that abstracts out database stuff, then behind that layer are "drivers" for each database (like PostgreSQL, MySQL, etc..). The drivers are called DBD, like DBD::Pg for PostgreSQL. But you don't use those drivers directly from your code; rather, you use DBI which sits in front of the drivers.

    But anyway, DBI can't be found. That means either it's not installed or isn't in the %INC path. So look for it with `locate DBI`. If you have to install it, use CPAN (as root type `cpan`, or maybe `perl -MCPAN -eshell`, then `install DBI` and `install DBD::Pg`. If you found DBI installed, then you might have to do something like "use lib '/path/to/DBI/'". So first, see if DBI is installed.

Re: PostgreSQL/Perl help Reformatted
by Hanamaki (Chaplain) on Nov 01, 2001 at 22:59 UTC
    Get DBI and the Postgresql driver DBD::Pg, install it as you install all modules, and you should be fine.

    Hanamaki
Re: PostgreSQL/Perl help Reformatted
by Anonymous Monk on Nov 01, 2001 at 23:36 UTC
    Thanx for the help!
    D.