Search code examples
perlsybase

How to access sybase with PERL


Here is what I have so far. I can not create the db connection.

#!/usr/local/bin/perl
require "sybutil.pl";
use Sybase::DBlib;
use DBI;
my $dbhandle=&opendb;
sub opendb{
    my $server ="abc.nam.aa.net";
    my $user = "sam";
    my $password = "abc123";
    #print "Connecting to $server as $user and $password\n";
    my $dbfh= new Sybase::DBlib($user, $password, $server);
    if(!defined($dbfh)) {
        die("Cannot connect to server.\n");
    }
    printf "Open database '%s' with id '%s' successful\n", $server, $user;
    return $dbfh;
}

How do I access sybase with PERL?


Solution

  • As I recall, the format for $server, should be the same as the entry in the interfaces file ($SYBASE/interfaces or %SYBASE%/sql.ini) for that particular server. It's ususally the same value as returned by the query select @@servername

    The hostname/ip and port are listed in the interfaces file, and the Sybase libraries will use that file to do the lookup.

    More information on this as well as code samples can be found at Michael Peppler's site. Michael maintains the Sybperl mailing list, and really has a great amount of information on his site.