PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: cached connections and keeping Sybase connection open
Date: Jul 16 2002 11:59PM

On Tue, 2002-07-16 at 16:43, Kafali, Utku (MED) wrote:
> 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)

This really depends on how you execute your CGI scripts. If your scripts
run in a "persistent" environment (e.g. apache/modperl) then the
connection *can* be kept between CGI requests - but that will probably
not happen automatically. You can look at Apache::DBI to provide
persistent connections.

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

Various issues:

> $ENV{'LD_LIBRARY_PATH'}="/local/sybase/12.0.0/OCS-12_0/lib:$ENV{LD_LIBRA
> RY_PATH}
> ";

Setting LD_LIBRARY_PATH here has no effect on the running process.

> 
> sub execute_sql
> {
>         local $dbh =
> DBI->connect("dbi:Sybase:server=SYBASE;database=$_[0];hostn
> ame='WEBMIN'", "sa","" );

Why "local" here? I think you mean "my".

However - in any case the connection that is opened here will go out of
scope when the subroutine exits. This will *automatically* trigger the
disconnect.

> sub login_sybase()
> {
>         $dbh =
> DBI->connect_cached("dbi:Sybase:server=SYBASE;database=$_[0];host
> name=WEBMIN", "$_[1]", "$_[2]" );
>         return $dbh;
> }

I'm not sure if connect_cached() works with DBD::Sybase. But in any case
you need to consider the persistence issues of your process (see my
answer under 1) above).

Michael
-- 
Michael Peppler / mpeppler@peppler.org / http://www.mbay.net/~mpeppler
mpeppler@zetatools.com / ZetaTools, Inc / http://www.zetatools.com
ZetaTools: Call perl functions as Sybase stored procedures!