DaWolf has asked for the wisdom of the Perl Monks concerning the following question:
Hi there
I'm trying to start programming a script that connects to a mySQL database using the DBI module. Well, so far so good, I can perfectly understand the syntax of it, but I have a real BASIC and VERY IMPORTANT question that is VITAL to start the whole thing.
I'll have to do most of the support for the implementation of this script, and the client have his database ready and a linux server where the site will be hosted, wich is great.
My question is: Where the database must be? How the server will "know" where the database is so when executes the connect call?
I know that maybe I'm posting something that doesn't have a DIRECT relation with perl, but I'm really desperate here, since it's my first job on SQL and DBI and I don't even know how the connection actually works....
If ANYONE can help me it would be gratefully appreciated.
Thanks in advance,
Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper
Re: Pretty technical DBI question
by btrott (Parson) on Nov 14, 2000 at 00:50 UTC
|
The database can be on either the local machine
(where you'll be running the application/tools), or
on another machine. When you connect to the DB,
you specify the hostname of the machine where the
database lives; if you don't give a hostname, the
local machine is assumed. From the docs (for
DBD::mysql):
The hostname, if not specified or specified as '',
will default to an mysql or mSQL daemon running
on the local machine on the default port for the
UNIX socket.
You'll need to look at the DBD::mysql docs, because
there is no standard on the manner in which the
hostname should be passed to the driver. The
docs suggest this DSN:
$dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
| [reply] [d/l] [select] |
Re: Pretty technical DBI question
by tame1 (Pilgrim) on Nov 14, 2000 at 00:57 UTC
|
The above is pretty accurate.
What I use is $db = "dbi:mysql:dbname:hostname:port";
so then:
my $dbh = DBI->connect($db, $user, $auth);
perldoc the DBI.pm, because I think you can do the hostname
settings inside the connect call as well, as in
my $dbh = DBI->connect("dbi:mysql:dbname", $user, $auth, $hostname, $port);
but my memory is hazy on that one.
Best bet - pod2text DBI.pm and read! OR buy Randy J. Yarger's
wonderful book, mSQL and MySQL, from O'Reilly. It covers
this question in full, with plenty of examples. | [reply] [d/l] [select] |
RE: Pretty technical DBI question
by boo_radley (Parson) on Nov 14, 2000 at 00:55 UTC
|
in addition to btrott's excellent advice, if you're working on a winxx system, be sure you've got all the information in the SQL.INI set up correctly. That will help the DBDs find your database. | [reply] |
|