Just some side-commands.

kejohm didn't say so, but he also dropped the double quotes around single scalar variables. They here only function as forced stringification of the two variables for user/password, wich disables undef (which is valid). I did include hist quotation fixes below. The optional arguments after the driver prefix (dbi:ODBC:) are seperated by semi-colons, not colons. User and password are not optional.

The DSN for ODBC is kinda special, please use 'perldoc DBD::ODBC::FAQ' to read all about it.

sub open_dbi { # Declare and initialize variables my $host = "192.168.1.3"; my $db = "d60380940"; # NEEDS QUOTES my $db_user = "root"; # NEEDS QUOTES my $db_password = "root"; # NEEDS QUOTES # Connect to the requested server # MySQL example my $dbh = DBI->connect ("dbi:mysql:$db:$host", $db_user, $db_passw +ord, { RaiseError => 1, # When expecting problems, EN +ABLE! PrintError => 1, # When expecting problems, EN +ABLE! ShowErrorStatement => 1, # When expecting problems, EN +ABLE! FetchHashKeyName => "NAME_lc", # Always be predictable in ke +y names }) or err_trap ("Cannot connect to the database"); # ODBC example semi-colon, not colon ---. ,------- Needs + Host= prefix my $dbh = DBI->connect ("dbi:ODBC:DSN=d60380940;Host=192.168.1.3", + undef, undef, { RaiseError => 1, # When expecting problems, EN +ABLE! PrintError => 1, # When expecting problems, EN +ABLE! ShowErrorStatement => 1, # When expecting problems, EN +ABLE! FetchHashKeyName => "NAME_lc", # Always be predictable in ke +y names }) or err_trap ("Cannot connect to the database"); return $dbh; }

Enjoy, Have FUN! H.Merijn

In reply to Re: Lost over DBI in perl by Tux
in thread Lost over DBI in perl by sdyates

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.