Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: DBI / Mysql connections

by monsieur_champs (Curate)
on Dec 03, 2004 at 11:24 UTC ( #412087=note: print w/ replies, xml ) Need Help??


in reply to DBI / Mysql connections

Dear cyril:
Sorry, but I think that you're wrong in assuming that the same connection will be reused every time you call DBI::Connect() with the same parameters. My experience says that this varies from DBD driver to DBD driver. Guess you shall use a cacheable implementation. Maybe Ima::DBI would be more appropriated.

An alternative solution could be provide a closure that knows about the database connection and Just Do The Right Thing:

#!/usr/bin/perl my $db_conn; { my $dbh = eval{ DBI::Connect( @params ) } or &RaiseError(); $db_conn = sub { return $dbh; }; } sub one{ my $db_conn = shift; my $dbh = &$db_conn; # use connection here... return; } sub two{ my $db_conn = shift; my $dbh = &$db_conn; # use connection here... return; }

About your second question, I guess the first contact is at the time you call DBI::Connect(): your password needs verification so the DBI/DBD engine makes sure you have authorization to connect to the specified database or if there is an error condition to be reported. Of course, this behavior depends on what DBD driver you're using.


Comment on Re: DBI / Mysql connections
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://412087]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-11-25 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls