Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2023-03-20 21:37 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.