To access Microsoft SQL server from unix, use the DBD:Sybase module.
In order to access SQL Server 2000 (and later) databases, you have to be sure that the DBD:Sybase module was built with the FreeTDS libraries.
Several *nix distributions have ready to install packages (for example, in Debian, you just need to install the packages 'libdbd-sybase-perl' and 'freetds-dev'); in case you need to install from sources, you need to do the following:
- install FreeTDS
Get the package from www.freetds.org, unpack it and execute make and then make install
- set the environment variable SYBASE
the environment variable should point to the location of FreeTDS (usually /usr/local/freetds):
SYBASE=/usr/local/freetds
export SYBASE - install DBD::Sybase
Get the package from cpan.org, unpack it and execute perl Makefile.PL (don't worry about testing errors here), then make and make install
Example:
#!/usr/bin/perl
#-- open database
use DBI;
my $dbh = DBI->connect('DBI:Sybase:server=192.168.0.1','user','password') or die $DBI::errstr;
$dbh->do("use Northwind");
#-- sample query
my $rows = $dbh->selectrow_array("SELECT COUNT(*) FROM Orders");
print "Orders has $rows records\n" if ( defined $rows );





