I have several perl scripts that connect to mysql databases. The only way I've gotten them to work is by hard coding the password in the DBI->connect statement. I'm running:

RHEL Servers 5.10
mysql 5.5.32
perl 5.8.8
DBI 1.52

If I use the following command the connect is successful:

my $dbh = DBI->connect('DBI:mysql:dns', 'userid', 'password' ) || die "Could not connect to database: $DBI::errstr";

This is a bad idea for obvious reasons! If I use:

my $dbh = DBI->connect('DBI:mysql:dns', $userid, $passwd ) || die "Could not connect to database: $DBI::errstr"

It fails with:

Usage: $class->connect([$dsn [,$user [,$passwd ,\%attr]]]).

I have tried it with $dsn both hard coded as above and with the variable $dsn set to the string as well as with $userid both hardcoded and a variable. I've tried both connects with and without the attribute field. The only format I have working is with the dsn, userid and password all hard coded. What am I overlooking or doing incorrectly?

Thanks for any help. <\p>


In reply to DBI->connect fails when password variable used by fmagee

Title:
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, details, 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, summary, 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.