Lunarpages Web Hosting Forum

Author Topic: Connecting to a mySQL db through PERL  (Read 994 times)

Offline SWAFO

  • Spacescooter Operator
  • *****
  • Posts: 30
    • http://www.breltech.com
Connecting to a mySQL db through PERL
« on: February 23, 2004, 03:55:28 PM »
Does anyone know the correct syntax to use to make the initial connection to a MySQL db in PERL?
Such as:
Code: [Select]
$dbh = DBI->connect ($db_name, $db_host, $db_user, $db_pass);

Thanks.

--SWAFO

Offline Ripta

  • Master Jedi
  • *****
  • Posts: 1271
Connecting to a mySQL db through PERL
« Reply #1 on: February 23, 2004, 08:45:56 PM »
SWAFO,

Code: [Select]

$dbh = DBI->connect("DBI:mysql:" . $db_name . ":" . $db_host, $db_user, $db_pass);


for example:

Code: [Select]

$dbh = DBI->connect("DBI:mysql:databasename:localhost", "username", "somepassword");


Where $dbh is the database handle  :P .
GetAFreelancer! (This service is not affiliated with Lunarpages)

Offline TWebMan

  • Quantum Encyclopedia Writer
  • *****
  • Posts: 3047
    • Take charge of your site
Connecting to a mySQL db through PERL
« Reply #2 on: February 24, 2004, 11:00:31 AM »
Looks about right, but but a line above that:

USE DBI;
"Computers cause people to make more mistakes than any other invention in history, with the possible exception of handguns and tequila."  - Unknown
"Liberty of any kind is seldom lost all at once." - D. Hume
Every day is an Ode to Joy
The planet will be fine... and so will your site

Offline Ripta

  • Master Jedi
  • *****
  • Posts: 1271
Connecting to a mySQL db through PERL
« Reply #3 on: February 24, 2004, 11:40:32 AM »
Yes, you will need:

Code: [Select]

use DBI;
$dbh = DBI->connect("DBI:mysql:databasename:localhost", "username", "somepassword");


Sorry about that. And,

Quote from: TWebMan

USE DBI;


I think Perl is case sensitive, unlike PHP which is case INsensitive. So, in Perl, "use" and "USE" are different.
GetAFreelancer! (This service is not affiliated with Lunarpages)