Solved

How to connect Sybase with perl?

Posted on 1998-12-07
3
466 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank You very much!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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…
This video discusses moving either the default database or any database to a new volume.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now