Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

(mysql) failing to locate object method

by sriraj (Initiate)
on Aug 03, 2004 at 08:38 UTC ( [id://379553]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks

I am trying to execute a program, where it has to collect

the data from the database table and to display but i am getting

an error while runnig the program Kindly help me

the error is as follows

(i am using mysql as a backend)

C:\ram>perl mysql4.pl <br></br> Content-type: text/html <br></br> <h>Software error:</h> <br></br> <pre>Can't locate object method &quot;connect&quot; via package &quot; +DBI&quot;<br></br> (perhaps you forgot to load &quot;DBI&quot;?) at mysql4.pl line 14.<br +></br> </pre><br></br> <p><br></br> For help, please send mail to this site's webmaster, giving this error + message<br></br> and the time and date of the error.<br></br> </p><br></br> [Tue Aug 3 13:57:18 2004] mysql4.pl: Can't locate object method "conn +ect" via <br></br> package "DBI" (perhaps you forgot to load "DBI"?) at mysql4.pl line 14 +.<br></br>

This is the error i am getting while i run the program

20040803 Janitored by Corion: Put error message into CODE tags

Replies are listed 'Best First'.
Re: (mysql) failing to locate object method
by davorg (Chancellor) on Aug 03, 2004 at 08:47 UTC

    Can we see the code? It's hard to debug stuff via telepathy. Currently my money would be on you not loading the DBI module in the program (like the error message suggests).

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      hi davorg

      thanks for immediate response and here the code which i am trying

      to execute,kindly help me

      use DBI; # Here's how to include the DBI module my $dbh; my $db = 'myfirstdatabase'; my $db_user = 'RAM'; my $db_password = ''; # Connect to the requested server $dbh = DBI->connect ("dbi:mysql:$db","$db_user", "$db_password",{Raise +Error => 0, PrintError => 0} ) or err_trap("Cannot connect to the dat +abase"); my $sql; my $sth; $sql = "SELECT max(unxtmstmp) FROM logfl"; $sth=$dbh->prepare($sql) or die "preparing: ",$dbh->errstr; $sth->execute or die "executing: ", $dbh->errstr; @$d = $sth->fetchrow_array; print "@$d";
        This program works for me, once I change $db, $db_user, $db_password, and $sql to something that exists on my system. Also I had to add a subroutine for err_trap(). Do you have the DBD::mysql module installed?
Re: (mysql) failing to locate object method
by beable (Friar) on Aug 03, 2004 at 08:51 UTC
    Not much to go on because you didn't show us your code. Could it be a syntax error on line 42? that you forgot to put in a line which says use DBI; ? Really you'd need to post the code that demonstrates the problem to get good help. You also might like to look at the documentation: DBI
Re: (mysql) failing to locate object method
by Gilimanjaro (Hermit) on Aug 03, 2004 at 11:09 UTC
    Could you post your *entire* code? The code you replies with earlier cannot be all of it; the error message includes a HTTP header, so you're probably using some other modules, one of which may be causing your DBI not to load. Also, please add use strict and use warnings to your code, and post the error messages again. They may be give a more precise indication of the problem...

      hi Gilimanjaro

      after doing modifications said by u only one error i am getting, the coding is as follows :==>

      use strict; use warnings; use DBI; # Here's how to include the DBI module my $dbh; my $db = 'myfirstdatabase'; my $db_user = 'RAM'; my $db_password = ''; # Connect to the requested server $dbh = DBI->connect("dbi:mysql:$db","$db_user", "$db_password",{Rai +seError => 0, PrintError => 0} ) or err_trap("Cannot connect to the d +atabase"); my $sql; my $sth; my $td; $sql = "SELECT max(unxtmstmp) FROM logfl"; $sth=$dbh->prepare($sql) or die "preparing: ",$dbh->errstr; $sth->execute or die "executing: ", $dbh->errstr; $td = $sth->fetchrow_array; print "$td";

      ==================================================

      The error which i am getting when i run the above program is

      C:\ram>perl timeinblt.pl Can't locate object method "connect" via package "DBI" (perhaps you fo +rgot to load "DBI"?) at timeinblt.pl line 14. C:\ram>

      the line no. 14 is

      $dbh = DBI->connect("dbi:mysql:$db","$db_user", "$db_password",{RaiseError => 0, PrintError => 0} ) or err_trap("Cannot connect to the database");

      Edited 3 Aug 2004, by footpad: Converted <br> tags to <P> tags and added <code> tags.

        This almost certainly means something is not right with your DBI installation... Try adding
        print "$_\n" for grep /^[a-z]/, keys %DBI::;
        after your 'use DBI;'. This single line will show you all symbols (including methods) in your DBI package after you've used it. If this list contains 'connect' then there's something wrong with your perl. If it doesn't, then something is wrong with your DBI. You could try reinstalling your DBI package maybe...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-19 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found