Hi,
Two questions:
(I am using: Solaris 8, Sybase ASE 12.0.0.4, DBI ver 1.28, DBD::Sybase
ver 0.94 )
1-) How can I use a database connection without entering user and
password repeatedly as far as the connection is valid? To be more
specific, from my cgi script I want to get user name and password from
the user and then use that connection until it is dead. (I don't want to
store password anywhere for successive database calls for security
reasons)
2-) It seems that I can not keep the connection open to database even
though I do not explicitly "disconnect". Below is part of the code that
I use to login to the database and execute sql:
# sybase-lib.pl
# common Sybase functions
do '../web-lib.pl';
use DBI;
# execute_sql(database, command, ?)
# execute some sql and return result
$ENV{'SYBASE'}="/local/sybase/12.0.0";
$ENV{'LD_LIBRARY_PATH'}="/local/sybase/12.0.0/OCS-12_0/lib:$ENV{LD_LIBRA
RY_PATH}
";
sub execute_sql
{
local $dbh =
DBI->connect("dbi:Sybase:server=SYBASE;database=$_[0];hostn
ame='WEBMIN'", "sa","" );
$dbh || &error("DBI connect failed");
local $sth = $dbh->prepare($_[1]);
$sth->execute() ;
local (@data, @row);
local @titles = @{$sth->{'NAME'}};
do {
while(@row = $sth->fetchrow_array()) {
push(@data, [ @row ]);
}
} while($sth->{syb_more_results});
#------- $sth->finish();
#------- $dbh->disconnect();
return { 'titles' => \@titles,
'data' => \@data };
}
# login_sybase(db, user, password)
# try to connect to the specific sybase database with user, password
given
sub login_sybase()
{
$dbh =
DBI->connect_cached("dbi:Sybase:server=SYBASE;database=$_[0];host
name=WEBMIN", "$_[1]", "$_[2]" );
return $dbh;
}
Any idea is greatly appreciated,
Thanks,
Utku Kafali