Solved

How to connect Sybase with perl?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

775 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