Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Establish Connection

by Anonymous Monk
on Jun 09, 2000 at 22:39 UTC ( [id://17396]=perlquestion: print w/replies, xml ) Need Help??

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

I am very very new to PERL, and quite ashamed to ask, thinking that my problem may just be really very simple to the monks. The following is my code:
#!/usr/bin/perl use strict; use DBI; #Connect to the database my $dbh= DBI->connect('DBI:mysql:my_database','my_name','my_password') + or die "Couldn't open database: "$DBI::errstr;stopped"; $dbh->disconnect();
Trouble is, when I run it just to check the connection, it gets an error at the third line of the code, the part which says "Use DBI;". Please, what could be wrong? I'm pretty excited to learn PERL..!

Replies are listed 'Best First'.
Re: Establish Connection
by Ovid (Cardinal) on Jun 09, 2000 at 22:56 UTC
    Do not, do not, do not be ashamed to ask questions like this. That's how you learn. When you first start out, even knowing where to look for the answers can be daunting.

    I have asked some pretty basic questions here and the monks have been very quick to respond with good advice and no flames. I've asked questions in other forums and I have often received replies like "Why don't you try the RTFM protocol?" (RTFM is 'read the f*&^#@g manual').

    Even when someone posts something which is critical of the original poster, it's usually fairly constructive and to the point. I'm new to Perl Monks, but I'm sold.

(jcwren) Re: Establish Connection
by jcwren (Prior) on Jun 09, 2000 at 22:44 UTC
    Most likely, you don't have the DBI module installed. Did you go out to CPAN, get a copy of it, and install it? Or do you know if your system administrator/ISP has installed it? As I recall, DBI doesn't come as part of the standard distribution.

    You can try 'perldoc DBI'. If you get an error "No document found for DBI", it's most likely not installed.

    --Chris
Re: Establish Connection
by plaid (Chaplain) on Jun 09, 2000 at 22:45 UTC
    For future reference, it would be immensely helpful if you could attach said error message with your posts, instead of just saying that there is an error. Without actually seeing the error, it's hard to arrive at any conclusion. That being said, are you sure DBI is installed? If so, does DBI currently work for any other scripts? Did it work at one point and just stop all of the sudden? With a bit more information, I'm sure we can be of assistance to you.
      I ran it, and it said: "Can't locate DBI.pm in @INC.. BEGIN failed--compilation aborted at line 3". My line 3 was the one that says "Use DBI". This is the first time I tried to se DBI. Reading from your reply, I am more positive that DBI wasn't installed. Thank you so much.
Re: Establish Connection
by btrott (Parson) on Jun 09, 2000 at 22:57 UTC
    Depending on the error message, either you don't have DBI (the likely culprit, as other posters have pointed out), or you don't have it installed correctly, or you're using Perl 4, which would give you a syntax error when reaching the use line.

    Post the error message and what you get when you do

    % perl -v
RE: Establish Connection
by cleen (Pilgrim) on Jun 11, 2000 at 07:03 UTC
    It sounds mostly like you dont have the DBI module installed just perl -MCPAN -eshell then install DBI

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-23 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found