Solved

How to connect Sybase with perl?

Posted on 1998-12-07
3
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

622 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