Important legal notice!

How to get DBI/DBD::Sybase working on Linux

by Philip Jacob
Last modified on November 9th, 2001

This document is very, very old. Proceed with caution.

Just a few notes before we get into the How-to itself...

This paper was originally written in the summer of 1998 and since then lots of things have changed. Notably:

  • Sybase released the Sybase ASE server for Redhat, Caldera, and S.u.S.E distribs of Linux. Included in this distribution are the coveted Ct-lib libraries that you can use to connect to a Sybase SQL Server or a Microsoft SQL Server.
  • Several revs of DBI have been released.
  • Several revs of Perl have been released.
  • Several revs of DBD::Sybase have also been released.

For those of you just starting out with DBD::Sybase on Linux, I think the path of least resistance for you might involve installing the entire Sybase ASE (to get Ct-lib installed), installing a recent version of Perl, and a recent distribution of Linux (80% of the email I get is from Redhat users, in case you care).

Note about Microsoft SQL Server:
Several people have asked if this procedure can be applied similarily to connect a Linux box to M$-$QL server. Some of these people have even tried it themselves. Some of the people who tried it themselves actually got it to work. My understanding is that since the Sybase servers and the Microsoft server were once the same piece of software, much of the underlying code as well as overall design is quite similar. So, that's the deal with that. If you're one of the people who have this setup working, please send me some comments about the process.


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.

Jonathan Fine <> apparently has this exact same setup running on Redhat 5.1. I 've snipped from his email and placed that here. I'm putting this wonderful piece of information here, because I consistently get emails from people asking why this won't work with Redhat 5.0. The reason has to do with the libc (glibc) that shipped with 5.0. Upgrade to 5.1 and save yourself some trouble.

Download all of the following software:  

  • The Client Library for Linux (already converted from a.out to ELF): ctlib-linux-elf.tar.gz
  • A replacement for isql.  Use sqsh for now, but be aware that there are other possiblities out there for you.
  • DBI.  I'm using version 0.90 right now.
  • DBD.  I'm using version 0.06 right now, but I believe version 0.08 is out.
  • Obviously, you need Perl. I used version 5.004_04 when I did this, but be aware that 5.005 is out. Can someone confirm whether this procedure works with 5.005 for me, please?
After you've downloaded all of that software, continue as described:
  1. Step 1: Installing the Client Library:

  2. 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  
    % tar xvf ctlib-linux-elf.tar  
    % gunzip sybase.tgz  
    % tar xvf sybase.tar  

    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:  

            query tcp eth0 5000  
            master tcp eth0 5000  
    The '' should be the IP address of the machine running your Sybase server. The "5000" refers to the port which the Sybase server is running on; it's the default, so you probably don't need to adjust that. This file just exists as /usr/local/sybase/interfaces and that's all.  

    Next, set some environment variables:  

    For tcsh users:  

    % setenv SYBASE /usr/local/sybase  
    % setenv DSQUERY SERVER_NAME (substitute from the respective value in your interfaces file)  
    % setenv SYBPLATFORM Linux  

    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.  

  3. Step 2: Installing sqsh:

  4. 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 
    sqsh-1.5 Copyright (C) 1995, 1996 Scott C. Gray 
    This is free software with ABSOLUTELY NO WARRANTY 
    For more information type '\warranty'  
    Password: ******* 
    1> select db_name()  
    2> go  

    (1 row affected)  

    Hopefully, that's working for you.  

  5. Step 3: Installing DBI:

  6. 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.

  7. Step 4: Installing DBD::Sybase:

  8. Ok, this is the tricky part.  Start to install the DBD module as follows: 

    % gunzip DBD-Sybase-0_06.tar.gz 
    % tar xvf DBD-Sybase-0_06.tar 
    % cd DBD-Sybase-0.06/ 

    Edit the PWD file so it reads as follows: 

    # This file contains optional login id, passwd and server info for the test 
    # programs:  
    # You probably don't want to have it lying around after you've made  
    # sure that everything works OK.  


    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 Exp $  
    # Configuration file for Sybperl  
    # Where is the Sybase directory on your system (include files &  
    # libraries are expected to be found at SYBASE/include & SYBASE/lib  

    # Additional libraries.  
    # Some systems require -lnsl or -lBSD.  
    # Solaris 2.x needs -ltli  
    # SGI IRIX needs -linsck (and may need need -ltli)  
    # DEC OSF/1 needs -ldnet_stub and may need -lsdna  
    # SunOS 4.x needs -linsck  
    # HP-UX 10.x needs -linsck  
    # AIX 3.2.5 needs -linsck  
    # Linux needs -lsybtcl and -linsck  
    # See the Sybase OpenClient Supplement for your OS/Hardware  
    # combination.  
    EXTRA_LIBS=-lsybtcl -linsck  

    # DBD::Sybase needs access to some C include files that are provided  
    # by the DBI module. These are normally found in # $Config{sitearchexp}/auto/DBI  
    # but if they are in some other place on your system then you can specify  
    # that directory here:  
    # DBI_INCLUDE=/usr/local/lib/perl5/site_perl/sun4-solaris/auto/DBI  

    # LINKTYPE  
    # If you wish to link DBD::Sybase statically  
    # into perl uncomment the line below and run the make normally. Then,  
    # when you run 'make test' a new perl binary will be built.  

    Ok, you're ready to start installing:  

    % perl Makefile.PL  
    % make  
    % make test  

    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.  

    Program 1:  

    #!/usr/local/bin/sperl -w  

    BEGIN {  
      $ENV{'SYBASE'}        = "/usr/local/sybase";  
      $ENV{'DSQUERY'}       = "SERVER_NAME";    #As listed in 'interfaces'  

    my (@available_drivers, $dbh, $sql_statement, $sth, @array) = ();  

    my ($data_source)       = "dbi:Sybase";  
    my ($username)          = "mylogin";  
    my ($password)          = "mypassword";  

    use DBI;  

    #Prints a list of the available DBD drivers.  
    @available_drivers = DBI->available_drivers;  
    print ("The available DBD drivers are: @available_drivers.\n");  

    #Connect to the Sybase db server.  
    $dbh = DBI->connect($data_source, $username, $password, 'Sybase')  
      || die "Can't connect: $DBI::errstr";  

    #Run a basic SQL statement.  
    $sql_statement = "select * from test";  
    $sth = $dbh->prepare($sql_statement)  
      || die "Can't prepare the SQL statement: $DBI::errstr";  
    $sth->execute || die "Can't execute the SQL statement: $DBI::errstr";  

    #Get the data back.  
    while (my($name, $phone) = $sth->fetchrow_array) {  
      print ("$name is available at $phone.\n");  

    #Destroy objects and close things down.  

If you have any questions, please email me.  I can't guarantee that I can definitely help, but it's worth a shot, right?  


Legal notice:  
I didn't write any of the software that I have linked from this page.  Program 1 listed above is just for demonstration purposes.  Just because I wrote this page doesn't mean that I will be responsible for any of the the consequences of using this software.  Use it at your own risk and have a nice day.