Gossamer Forum
Home : General : Perl Programming :

Working with MySQL and Strict

Quote Reply
Working with MySQL and Strict
I have a question about connecting to mysql while using strict and required files.

I start the executed file with:
$dbh = DBI->connect("DBI:mysql:test:localhost")

But whenever I try and call the $dbh variable in the required file:
$sth = $dbh->prepare

I get errors, so I have to connect again. I think this is probably very inefficient. Any ideas what to do?



Quote Reply
Re: Working with MySQL and Strict In reply to
your $dbh variable is not global..

the most efficient way is to keep passing it to other subroutines..

but that is annoying..

the easy way is just to put use vars.pm..

use vars qw/$dbh/;

and it globalizes $dbh to every subroutine without the need to pass it.. (even in strict)

Jerry Su
Quote Reply
Re: Working with MySQL and Strict In reply to
I've already done that. The problem is that I am trying to pass the variable to a sub in another file, a required file.

Any ideas?

Quote Reply
Re: Working with MySQL and Strict In reply to
just create another session in that file.. even Links SQL creates sessions in most of the subroutines in sub files..

Jerry Su