Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Lost over DBI in perl

by kejohm (Hermit)
on Aug 22, 2011 at 02:04 UTC ( #921570=note: print w/replies, xml ) Need Help??


in reply to Lost over DBI in perl

First off, you want to be running under strict and warnings. This will catch any errors that you may have in your strict, so put this at the top of your code:

use strict; use warnings;

(You could also use diagnostics for more verbose messages.)

This means that for your sample, you will need to quote the database name, user name and password, so Perl won't complain when it finds an unknown bareword.

In order to specify a particular host to connect to, use the 'host' parameter in the data source, eg:

sub open_dbi { # Declare and initialize variables my $host = '192.168.1.3'; my $db = 'd60380940'; my $db_user = 'root'; my $db_password = 'root'; # Connect to the requested server # my $dbh = DBI->connect("dbi:mysql:database=$db;host=$host", $db_u +ser, $db_password, {RaiseError => 0, PrintError => 0} ) or err_trap(" +Cannot connect to the database"); my $dbh = DBI->connect("dbi:ODBC:database=$db;host=$host", $db_use +r, $db_password, {RaiseError => 0, PrintError => 0} ) or err_trap("Ca +nnot connect to the database"); return $dbh; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://921570]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2016-12-05 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (82 votes). Check out past polls.