in reply to Writing DB Module using MethodMaker - Some More methods Added..
The last line should contain "1;" that is the successful return value from package ( that is missed out from the sample given by Vishi )package MakerDB; use strict; use warnings; use Carp; use DBI; use Data::Dumper; my $dbh; my $dbobj; use Class::MethodMaker get_set => [ { -read_cb => sub { my $self = shift; my $dsn = 'DBI:mysql:mydb'; my $dbuser ='root'; my $dbpass = ''; eval { $dbh=DBI->connect($dsn, $dbuser, $dbpass, { RaiseError => 1, AutoCommit => 0 } ); }; croak "\n\ncould not connect : $@" if $@; return $dbh; } },'connect' ], new => 'new'; 1;
use strict; my $vObj = MakerDB->new(); print "\n\tSuccessfully connected to DB\n\n" if my $dbhandle=$vObj- +>connect(); my $sth=$dbhandle->prepare("SELECT NAME, PASSWORD FROM userlog"); $sth->execute(); my $href; while ($href=$sth->fetchrow_hashref()) { print "\n"; print Dumper $href; }
2005-10-24 jdporter edited: added code and br tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Writing DB Module using MethodMaker
by vishi83 (Pilgrim) on Oct 24, 2005 at 11:27 UTC |