Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
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; }


Comment on Re: Lost over DBI in perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-04-18 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls