For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2007 > Error:Can't locate object method "prepare" via package "abc" at x









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Error:Can't locate object method "prepare" via package "abc" at x
Alma

2007-05-31, 6:59 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com