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

Hi, I've had a Perl script I wrote running properly on my server for months, and somehow a problem just popped up. When you submit the form on one of my pages it generates an error:
Software error: Can't call method "prepare" on an undefined value at mygames/registrat +ion.pl line 7. For help, please send mail to the webmaster (games@allthingsfree.com), + giving this error message and the time and date of the error.
Line 7 the error refers to:
$sth = $dbh->prepare("SELECT email FROM users WHERE LCASE(email) = '$r +egemail'");
Can anyone suggest what could be wrong?

Edit Masem 2001-11-28 - Code tags

Replies are listed 'Best First'.
Re: DBI issue
by Masem (Monsignor) on Nov 29, 2001 at 00:36 UTC
    The error means that your $dbh variable is undefined. Since earlier you probably create your database connection and define this variable, it means a few possible problems:
    • The DB server could be down.
    • The DB server is unaccessible.
    • The DB server user and password could have changed.
    You should check the status of the server using command line tools to make sure that you can access it (authenticated if necessary). If the user and password have changed, that's easily fixed in your script, otherwise, you need to make sure your DB server is operating properly.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

      I want to add that if you were checked what returns DBI->connect then the reason of this problem would be obvious to you. Something like:
      my $dbh = DBI->connect(....) or die $DBI::errstr;

      Another option for handling of DBI errors is usage of exceptions. DBI->connect has option RaiseError which can enable thowing exceptions if there exist any problem.

      my $dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1 });
      In former case you don't need to check what DBI->connect returns. Instead you should put this code inside eval block if you want to handle errors.
Re: DBI issue
by runrig (Abbot) on Nov 29, 2001 at 00:59 UTC
    Its likely your connect() is failing. You should be checking the status of your connect like so:
    # Some possibilities my $dbh = DBI->connect(..., {RaiseError=>1}); or my $dbh = DBI->connect(...) or die $DBI::errstr; or my $dbh = eval { DBI->connect(..., {RaiseError}=>1) }; redirect_to_some_friendly_page_that_says_our_database_is_down($@) if $ +@;