package My::DBU;
use strict;
use warnings;
use diagnostics;
use CGI::Carp;
use DBI;
sub new {
my $class = shift;
my $self = bless {}, $class;
my $dbh = shift || return undef;
$self->{dbh} = $dbh;
return $self;
}
sub begin_work{
my $self = shift;
$self->{dbh}->begin_work;
}
sub execute {
my $self = shift;
my $query = shift;
my $sth = $self->{dbh}->prepare($query);
my $rows = $sth->execute or die $DBI::errstr;;
return \$sth;
}
####
my $dbh = DBI->connect('DBI:mysql:db:localhost',
${dbuser},${dbpass}) or confess "$DBI::errstr
";
my $dbu = new My::DBU $dbh or confess "$DBI::errstr
";
$dbu->begin_work();
print "BEFORE ERR
";
my $sth = $dbu->execute( \$dbh, \$query, \$errmsg );
print "NEVER GETS HERE
";
####
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REF(0xaaa3700)' at line 1 at /usr/lib/perl5/site_perl/5.8.8/My/DBU.pm line 96.\n
####
http://www.perlmonks.org/?node_id=324671
http://www.perlmonks.org/?node_id=870145