Posts Tagged ‘sql’

PERL connect to SQL server

Monday, November 17th, 2008

To connect you PERL application to an SQL server is pretty easy.

First you need the driver for supporting SQL connections.

Install driver:

  1. Open command prompt
  2. Typ: ppm install DBD-mysql

After a correct installation of the driver your SQL connection can be made as follow:

#!/usr/local/bin/perl
print "Content-type:text/html\n\n";

use DBI;

$username = '';
$password = '';
$database = '';
$hostname = '';

$dbh = DBI->connect("dbi:mysql:database=$database;" .
 "host=$hostname;port=3306", $username, $password);

This is all you need to connect to your server.
If you don’t know your server ip, try connecting to your website address.

A very good website about this subject is:
http://www.codeproject.com/KB/perl/perldbi.aspx