LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-19-2010, 06:55 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
DBD::Sybase cgi script


Hi all,
please look at the following sample code that execute some database connectivity functions using DBI perl module.
Code:
#!/usr/bin/perl
BEGIN
{
$ENV{'SYBASE'} = '/usr/local/freetds';
$ENV{'LD_LIBRARY_PATH'} = '/usr/local/freetds/lib';
}
use CGI;
use CGI::Carp;
use DBI;
my $cgi = new CGI();
print $cgi->header();
my $cgi = new CGI();
my $path='/opt/ash/netcool';
my $hostname="192.168.2.95";
my $portno="4100";
my $database_name="NCOMS";
my $db_username="root";
my $db_password="access";
print <<EOF;
<html>
<head>
<title>DBD Sybase Connection Check</title>
</head>
<body>
<form name="myform">
EOF
print "\nSyabse:$ENV{'SYBASE'}<br>LD_LIBRARY_PATH:$ENV{'LD_LIBRARY_PATH'}<br>";
print "<h2>**********----->$dbh<-----**********</h2>";
my $dbh = DBI->connect("dbi:Sybase:host=$hostname;port=$portno;server=$database_name;",$db_username,$db_password) || warn "Database Connection
 not made: $DBI::errstr";
print "<h2>**********$dbh**********</h2><br>";
print <<EOF;
<br>
</form>
</body>
</html>
EOF
The output when I execute this sample code:
In console, without setting SYBASE=/usr/local/freetds and LD_LIBRARY_PATH=/usr/local/freetds/lib is
Code:
[root@station34 cgi-bin]# ./dbdsybase.cgi 
Content-Type: text/html; charset=ISO-8859-1

<html>
<head>
<title>DBD Sybase Connection Check</title>
</head>
<body>
<form name="myform">

install_driver(Sybase) failed: Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Sybase/Sybase.so' for module DBD::Sybase: libct.so.4: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230.
 at (eval 8) line 3
Compilation failed in require at (eval 8) line 3.
Perhaps a required shared library or dll isn't installed where expected
 at ./dbdsybase.cgi line 29
Syabse:/usr/local/freetds<br>LD_LIBRARY_PATH:/usr/local/freetds/lib<br><h2>**********-----><-----**********</h2>[root@station34]
In console, by setting SYBASE=/usr/local/freetds and LD_LIBRARY_PATH=/usr/local/freetds/lib is
Code:
[root@station34 cgi-bin]# ./dbdsybase.cgi 
Content-Type: text/html; charset=ISO-8859-1

<html>
<head>
<title>DBD Sybase Connection Check</title>
</head>
<body>
<form name="myform">

Syabse:/usr/local/freetds<br>LD_LIBRARY_PATH:/usr/local/freetds/lib<br><h2>**********-----><-----**********</h2><h2>**********DBI::db=HASH(0x87e56cc)**********</h2><br><br>
</form>
</body>
</html>
On browser
Code:
Syabse:/usr/local/freetds
LD_LIBRARY_PATH:/usr/local/freetds/lib
**********-----><-----**********
which means that the part
Code:
my $dbh = DBI->connect("dbi:Sybase:host=$hostname;port=$portno;server=$database_name;",$db_username,$db_password) || warn "Database Connection not made: $DBI::errstr";
print "<h2>**********$dbh**********</h2><br>";
print <<EOF;
<br>
</form>
</body>
</html>
EOF
of the script is not executing due to problem in connect statement. Why is this happening?
Also, why $DBI::errstr is not printing here.

Please assist me.

Thanks in advance.

Last edited by ashok.g; 07-19-2010 at 06:56 AM.
 
Old 07-20-2010, 12:14 AM   #2
sag47
Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 687
Blog Entries: 21

Rep: Reputation: 133Reputation: 133
Start your script with...
Code:
#!/usr/bin/perl -wT
use strict;
Does the output change at all to hint at the problem?
 
Old 07-20-2010, 01:34 AM   #3
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by sag47 View Post
Start your script with...
Code:
#!/usr/bin/perl -wT
use strict;
Does the output change at all to hint at the problem?
Thanks for your reply.

Ok. I made some changes to the script as you mentioned.
Here is the chaged script.
Code:
#!/usr/bin/perl -wT
use strict;
BEGIN
{
$ENV{'SYBASE'} = '/usr/local/freetds';
$ENV{'LD_LIBRARY_PATH'} = '/usr/local/freetds/lib/:/lib/:/lib/tls/';
}
use CGI;
use CGI::Carp;
use DBI;
my $cgi = new CGI();
print $cgi->header();
my $path='/opt/ash/netcool';
my $hostname="192.168.2.95";
my $portno="4100";
my $database_name="NCOMS";
my $db_username="root";
my $db_password="access";
print <<EOF;
<html>
<head>
<title>DBD Sybase Connection Check</title>
</head>
<body>
<form name="myform">
EOF
foreach (sort keys %ENV)
{
        if (($_ eq 'SYBASE')||($_ eq 'LD_LIBRARY_PATH')||($_ eq 'USER'))
        {
                print "$_ : $ENV{$_}<br>";
        }
}
my $dbh = DBI->connect("dbi:Sybase:host=$hostname;port=$portno;server=$database_name;",$db_username,$db_password) || warn "Database Connection not made: $DBI::errstr";
print "<h2>**********$dbh**********</h2><br>";
print <<EOF;
<br>
</form>
Even now I am not able to get the dbi connection here in browser.

Last edited by ashok.g; 07-20-2010 at 01:37 AM.
 
  


Reply

Tags
cgi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a Script to shutdown a service when a Sybase table reads over a certain count d-cam Linux - Server 2 08-11-2009 06:07 AM
calling CGI script in CGI script ravi_chobey Programming 3 03-19-2009 12:36 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
Can't install DBD::mysql or DBD::Pg DogTags Mandriva 2 01-21-2004 07:13 AM


All times are GMT -5. The time now is 04:40 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration