Inherit a database connection object
- From: patrikh@xxxxxxxxxxxxxxxxxxxxx (Patrik Hasibuan)
- Date: Mon, 25 Jun 2007 01:14:36 +0700
Dear all,
I am still new in Perl especially in its OOP concept.
I want to write once a script as a part of building a connection to my MySQL DB server. The parts only use a kind of vabiable such as "$dbh". Is it possible?
================
main.pl
================
#!/usr/bin/perl -w
use iterdir;
$namadir=iterdir->baru;
$namadir=iterdir->bukadir;
================
================
package kueri;
use DBI;
sub baru{
my $kelas = shift;
}
sub konek{
$dbh=DBI->connect("DBI:mysql:arsipan;localhost:3306","root","dearest") or die "gagal konek ke mysql";
}
1;
================
package iterdir;
use kueri;
sub baru{
my $kelas = shift;
}
sub bukadir{
my $kelas = shift;
$rootdir="/home/patrikh/sementara/tes";
opendir("dirku", "$rootdir");
$statusp=chdir($rootdir);
if ($statusp){
print "berhasil membuka direktori-->$rootdir\n";
while ($entridir=readdir("dirku")){
print "$entridir\n";
$sqlku=kueri->baru;
$sqlku=kueri->konek;
$sth=$dbh->prepare("insert into tblarsip (location, informasi) values ('$entridir', '')");
$sth->execute;
$sth->finish;
}
} else{
print "gagal membuka direktori yang diinginkan: $rootdir\n";
exit 1;
}
}
1;
================
The error message is:
"
Can't call method "prepare" on an undefined value at iterdir.pm line 22.
"
Please tell me how a class inherits connection object to the another class.
Thank you very much in advance.
--
Patrik Hasibuan <patrikh@xxxxxxxxxxxxxxxxxxxxx>
Junior Programmer
.
- Follow-Ups:
- Re: Inherit a database connection object
- From: Tom Phoenix
- Re: Inherit a database connection object
- Prev by Date: Re: Perl vs. Java for string manipulation & regex
- Next by Date: Re: Proper class setup?
- Previous by thread: Fwd: DELIVERY FAILURE: Delivery time expired
- Next by thread: Re: Inherit a database connection object
- Index(es):