Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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 = ''; 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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2018-05-24 04:37 GMT
Find Nodes?
    Voting Booth?