[Koha-devel] about C4Connect

Gynn Lomax Gynn at katipo.co.nz
Mon Jun 10 17:24:02 CEST 2002


> I i'm right, every DB function begins by a $dbh=&C4Connect.
> Connecting to a DB is a HIGH time-cost function.
> The solution to this problem would be to have only one $dbh=&C4Connect
> at the beginning of every .pl script, this $dbh variable being used by
> every sub.
> One solution would be to rebuild all sub calls to add a dbh parameter,
> but i'm sure there is a solution to declare a global variable, which
> would be used if there is no "my $dbh" in the .pm sub...
> What's the best solution in Perl to do this ? ("our" may be used with
> packages, but what i want is to have the C4Connect at the beginning of
> every .pl script)

My solution would be to create a global $dbh in the .pm that has the
C4Connect sub. You can get a .pm to execute some code at the time that it is
loaded (see package Constructors and Deconstructors in the perl man pages)-
which would allow you to connect to the database. And when the script ends,
you can disconnect from the database.

I don't know if this is the best solution, but at least it would get it down
to one connect per script call.

Gynn.





More information about the Koha-devel mailing list