develooper Front page | perl.beginners | Postings from May 2007

Error:Can't locate object method "prepare" via package "abc" at xyz.pm

Thread Next
From:
Alma
Date:
May 31, 2007 15:49
Subject:
Error:Can't locate object method "prepare" via package "abc" at xyz.pm
Message ID:
1180617470.727212.109630@q19g2000prn.googlegroups.com
Hi ,

Urgent help.

I have written 2 modules one abc.pm & xyz.pm (admin modules).

abc.pm
--------------------------------------
my $databasehandle;

sub new($){

    my ($self,$usr,$pwd) = @_;
    $usr||= "test";
    $pwd ||= "test123";
    ($self) = {};
    bless($self);
    $databasehandle = DBI->connect("DBI:Pg:dbname=mydb",$usr,$pwd,
{PrintError =>1});

        if (!$databasehandle){

                print "Database connection is not estabilished";
                exit;
                             }
        return($self);
        }


sub DESTROY(){
my $self;
$self->disconnect();
}

sub disconnect(){
        $databasehandle->disconnect() if ($databasehandle);
}




xyz.pm
----------

package admin;
use DBI;
use Apache::DBI;
use CGI;
use abc;
use strict;


my $database_handle =();

sub new()
{
my $self={};
bless($self);
$database_handle = abc->new('test','test123');
if (!$database_handle){

print "connection cant done:";
return -1;

}
print " connection done:";
return $self;

}

sub display()
{
my $self = shift;
my $sth = $database_handle->prepare("select * from table where status
='P'");
print $sth;
my $res =$sth->execute();
my @row = $sth->fetchrow_array();
print @row;
return $res;
}


I am getting an error :
Can't locate object method "prepare" via package "abc" at xyz.pm

Is it not possible the way i am trying...can anyone tell me where i am
wrong.

Thanks ,
Alma


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About