Solved

How to connect Sybase with perl?

Posted on 1998-12-07
3
483 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Port 80 requests 16 102
stftime format 4 58
How to search multiple patterms in a file with perl? 4 85
Perl Awk Need Help 3 136
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…
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.…
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…

685 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