http://www.perlmonks.org?node_id=921570


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 usediagnostics 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; }