You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Levon Barker <le...@cam.ca> on 2003/10/23 18:45:29 UTC

DBI : Is this the right way to do it?

Hello,

Can someone verify that this is the right way to use DBI and mod_perl (with
Apache::DBI of course). I get problems where if the user cancels a request
before my module has finished accessing my Oracle db, the module does not
work for any ongoing requests until I restart the Apache server. This is not
real code but an example of how I am putting it all together.

################ START OF CODE SNIPPET ###########

package SomeModuleWhichShowsUpAsaAPage;

my $dbh = DBI->connect ( 'dbi:Oracle:paprodi','test', 'test',
			            {
			               RaiseError => 1,
			               AutoCommit => 0
			            }
			) || die "Oracle database connection not made";

my $sql = "select title from industry where id = ?";
my $sth = $dbh->prepare($industrySql);

sub handler {
	my $r = shift;
	my $id = $r->param('id');
	$r->send_http_header('text/html');
	print &get_industry_str($id);
	return OK;
}

sub get_industry_str {
	my $id = shift;
	$sth->execute($id);
	my $title;
	$sth->bind_col( 1, \$title);
	$while ($sth->fetch) {
	}
	return $title;
}

#################### END OF CODE SNIPPET ##################

When a user does cancel the request before the db access has finished, I get
this in my error log the next time a user tries to call the page:


Levon Barker