Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

In reply to Re: DBI / Mysql connections by monsieur_champs
in thread DBI / Mysql connections by cyril

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (13)
    As of 2018-07-23 13:41 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (468 votes). Check out past polls.