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.