brent.allsop has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I’m trying to get an apache::asp application using MySQL up and running on a new server. It does the following:

my $dbh = DBI->connect_cached($dsn, $user, $password, { RaiseError => +1, AutoCommit => $autocommit });
But I’m getting:

Can’t locate object method connect_cached via package DBI

But I don’t know what this could mean. Does it seem to mean I’m using the wrong version of DBI? One that doesn’t have a connect_cached call? Or maybe, do I not have the MySQL stuff installed properly. I’m not sure what to do next to resolve this problem.

Thanks Monks!

Brent Allsop

Replies are listed 'Best First'.
Re: No DBI->connect_cached?
by GrandFather (Saint) on Sep 03, 2007 at 02:08 UTC

    Have you a use DBI; line in your code? Did you copy and paste the error message, or have you "cleaned it up" for us?


    DWIM is Perl's answer to Gödel
      Yes, I have the following in my startup.pl:
      use DBI; use DBD::mysql;
      And here is the exact error from the apache error log:
      [Sun Sep 02 20:40:30 2007] [error] [asp] [4441] [error] Can't locate o +bject method "connect_cached" via package "DBI" at /usr/local/webtool +s/func.pm line 75. <--> , /usr/lib/perl5/site_perl/5.8.8/Apache/ASP.p +m line 1521
      Here is the func.pm line 74 and 75 the asp script calls:
      my $dsn = 'DBI:mysql:database=canonizer_devel_3:host=localhost;port=33 +06'; my $dbh = DBI->connect_cached($dsn, $user, $password, { RaiseError => +1, AutoCommit => $autocommit });
        IIRC it is not enough to list the modules you use in startup.pl, you must still use them in your scripts itself. startup.pl just does some pre-loading only, so you save time when running your scripts.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        I wonder if there is a mismatch between the Apache::DBI version and the version DBI expects to see? From the DBI docs:

        However, if Apache::DBI is loaded then connect_cached will use it.

        DWIM is Perl's answer to Gödel
Re: No DBI->connect_cached?
by jZed (Prior) on Sep 03, 2007 at 05:58 UTC
    Since the DBI changes log lists connect_cached() added in 1999 at version 1.07, it's unlikely you have a version of DBI that lacks it, which makes that a puzzling error message. I'd guess some weird interaction with Apache::DBI. You might want to send your question to dbi-users@perl.org if no one here comes up with an answer.
Re: No DBI->connect_cached?
by perrin (Chancellor) on Sep 03, 2007 at 04:49 UTC
    What's the version number of your installed DBI?