At 11:04 AM 5/9/00, Wim Kerkhoff wrote:

>Snip [...]


Hmmm. Well, some things to look at:

globals aren't too good (i.e. use vars qw(...) ). Best to "localize" with my();

What's the SQL statement look like?

$sth->fetchrow returns an array but I don't know off the top of my head if 
it automagically becomes an array ref if assigned to a scalar.

Are you checking your return values?

Are getting any funny looking result sets? i.e., data from the last query? 
That's usually the big red light indicating a big leak. There's docs on 
that in the guide.

I hope you are also doing some error checking that you left out for the 
example, i.e. :

         $dbh->connect() or die "There was an error:",
                 $DBI::errstr, "\n";

You might also undef whatever variable is holding the result set when you 
are done working it.

Just remember that you can use Apache::DBI to fire up a connection to the 
dB when Apache starts. Any time you make a DBI->connect() call, Apache::DBI 
will intercede and use it's cached handle.

Beyond these points what's here seems reasonable.

HTH.

--Jeff



>#!/usr/bin/perl -w
>
># some sample code
>use strict;
>use MyStuff;
>use vars qw ($dbh $foo $bar $sql $sth $rc);
>
>$dbh = dbConnect;
>
>sub something {
>         $foo = "somevvar";
>         $sth = $dbh->prepare("some sql code");
>         $sth->execute();
>         $bar = $sth->fetchrow();
>         $sth->finish;
>}
>
>----------------------------------
>
>package MyStuff;
>
>use strict;
>use DBI;
>
># export dbConnect, etc
>
>sub dbConnect {
>         my $dbh = DBI->connect(args,to,dbi);
>         return $dbh;
>}
>1;
># end of MyStuff;
>---------------------------





Jeff Beard
_____________________________________________
Web:            www.cyberxape.com
Email:          jeff at cyberxape.com
Location:       Boulder, CO, USA



Reply via email to