How to get DBI/DBD::Sybase working on Linux
by Philip Jacob
This document is very, very old. Proceed with caution.
Microsoft SQL Server:
Hector has some instructions about talking to MS-SQL Server 7.0 using DBD::Sybase and FreeTDS.
Scott Bradley apparently has DBD::Sybase running on Redhat Linux 6.0 talking to an MS-SQL server. I think this will be of interest to those of you who are looking for up-to-date info on interfacing with this particular Microsoft product. I've snipped from his email and placed that here.
The Original How-To Document
The purpose of this doc is to explain how to get DBI/DBD::Sybase and the necessary supporting software to work on Linux. DBI is a standard perl interface to several well-known databases. I've personally tested this on an out-of-the-box distribution of Redhat 4.2. I'm sure that this process will work similarily, if not identically, on other Linux distributions; please let me know if you have any luck with another version.
Download all of the following software:
Login as root on your target machine. If you don't have root access on your machine, I think you can still get this to work, but you're on your own..... Sorry! Copy ctlib-linux-elf.tgz to /usr/local/sybase (if it doesn't exist, mkdir /usr/local/sybase ) and extract all of the files contained within:
% gunzip ctlib-linux-elf.tgz
Now, make an interfaces file. This file contains information that the Client Library needs to connect to your Sybase database server. My interfaces file looks something like this:
Next, set some environment variables:
For tcsh users:
% setenv SYBASE /usr/local/sybase
Now, cd /usr/local/sybase/sample/ctlibrary and try and compile the example scripts:
% make all
If this doesn't work, you're probably screwed, but I
can't guarantee that! Otherwise, congrats- you've just installed the
Linux Client Library and saved yourself as much as USD $795.
You don't actually need this, but my guess is that you'll want it. Installing it gives you command line access to your Sybase server as well as affording you an opportunity to see if your Client Library is functioning correctly. My experience is that sqsh usually installs without hassle.
After you've installed it, check to see if it works:
% sqsh -SSERVER_NAME -Uusername_on_sybase_server
(1 row affected)
Hopefully, that's working for you.
DBI pretty much installs painfree as well. In order to use the latest version (0.90 as of this date), you must have Perl 5.004 or higher installed. I haven't discovered any useful tricks here. Remember what I said earlier... that I haven't tried this with 5.005, but I'd like to know if it worked for you.
Ok, this is the tricky part. Start to install the DBD module as follows:
% gunzip DBD-Sybase-0_06.tar.gz
Edit the PWD file so it reads as follows:
# This file contains optional login id, passwd and
server info for the test
Note: the SERVER_NAME value should be listed in your interfaces file (see Step 1).
Then, edit the CONFIG file so it reads as follows:
# $Id: CONFIG,v 1.3 1997/10/31 18:59:46 mpeppler
# Additional libraries.
Ok, you're ready to start installing:
% perl Makefile.PL
This last step will cause a bunch of errors!!! Don't freak out. Edit the file in
and take out the reference to -ltcl altogether so it reads:
-L/home/sybase/lib -lct -lcs -lcomn -lintl -lsybtcl -linsck -lm
Run a make test again and it works fine. You now have a statically linked perl binary sitting in your current directory. I would suggest copying this executable to /usr/local/bin and naming it something like sperl.
To use this new binary in for your scripts, you'd begin your .pl files as shown in the example script below.
my (@available_drivers, $dbh, $sql_statement, $sth, @array) = ();
#Prints a list
of the available DBD drivers.
#Connect to the
Sybase db server.
#Run a basic
#Get the data
and close things down.