Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2015-11-26 17:09 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (704 votes), past polls