Solved

How to connect Sybase with perl?

Posted on 1998-12-07
3
476 Views
Last Modified: 2011-10-03
I have try to connect the Sybase with the program as follow:

However, the server reply that the Sybase/DBlib is not found and cause the compilation error.

Can anyone tell me how and where to get the DBlib and CTlib?
Is there any special condition to install these library since i am not the system admin?

Also, can anyone give me some code (or sample code that can connect to the Sybase)?
Thank you very much!

The following is my code:

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

use Sybase::DBlib;
$dbh = new Sybase::DBlib 'user', 'password';
$dbh->dbcmd("select name, category from product");
$dbh->dbsqlexec;
$dbh->dbresults;
while(@data = $dbh->dbnextrow)
{
      foreach $data (@data)
      {
            print $data;
      }
}

exit;
0
Comment
Question by:CWL
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 150 total points
ID: 1206786
download and install

http://www.perl.com/CPAN-local/authors/Michael_Peppler/sybperl-2.10.tar.gz

Also, you forgot the

$dbh->dbuse('db_name')

before the dbcmd.  In fact, if you wanted, your entire code could be recast as:

#!/usr/local/bin/perl -w
use strict;
use Sybase::DBlib;

print "Content-type: text/html\n\n";

my($user) = 'user_name';
my($passwd) = 'password';
my($server) = 'server';
my($db) = 'database';

die "Unable to login to $server as $user\n" unless
    $dbh = Sybase::DBlib->dblogin($user, $passwd, $server) &&
    $dbh->dbuse($db);

$dbh->sql('select name, category from product',
                sub {
                      foreach (@_) {
                             print "$_\n";
                      }
                      print "-----------------------\n";
               });
$dbh->dbclose;


my($dbh);

0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206787
Sorry, additionally, if you can't get your administrator to install it properly, follow the following to install it locally.

1.) unpack the distribution someplace reasonable.
2.) Determine where you want it to go (say ~/sybperl)
3.) from the unpacked directory, give the command

perl -Makefile.PL LIB=~/sybperl

4.) After reading the readme file, and adjusting files according to instructions therein, give the commands:

make
make test
make install

5. In your code, use

use lib '~/sybperl';

before the

use Sybase::DBlib;

0
 

Author Comment

by:CWL
ID: 1206788
Thank You very much!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question