DB request
| From: | Sam Liddicott | Date: | Tue, 14 May 2002 11:14:32 +0000 |
| Subject: | DB request | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-1368@lists.php.net to get a copy of this message | ||
It can be expensive to keep a DB connection open while the user downloads a
long page generated by a report of that page.
We have this case, the reports are very inexpensive, but it takes a long
time for the page to be downloaded.
I would like to disconnect the DB while this happens and then (without
hassle) connect again on-demand if I need to use that connection again.
In DB/pgsql.db
function connect($dsninfo, $persistent = false)
{
if (!DB::assertExtension('pgsql'))
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
$this->dsn = $dsninfo;
...
We see that after one connection $dsninfo is stored in $this->dsn.
So why does dsninfo need to be passed on a second call to connect?
Why not:
function reconnect()
{
if (!DB::assertExtension('pgsql'))
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
if ($this->dsn===false) return $this->raiseError(DB_NOT_CONNECTED);
if ($this->connection) $this->disconnect();
return $this->connect($this->dsn);
}
Thus reconnect can be called without parameters to reconnect.
Then for each function we can have as the first line:
if (! $this->connection) $this->reconnect();
Which means the DB connects on demand, reconnects on demand etc.
Of course to solve my problem I'll do it the hard way finding all the places
that might need to use DB and reconnecting there...
But this I feel would add to PEAR DB
Sam
_____
Samuel Liddicott
Support Consultant
sam@ananova.com <mailto:sam@ananova.com>
Direct Dial: +44 (0)113 367 4523
Fax: +44 (0)113 367 4680
Switchboard: +44 (0)113 367 4600
Ananova Limited
Marshall Mill
Marshall Street
Leeds
LS11 9YJ
http://www.ananova.com
Registered Office:
St James Court
Great Park Road
Almondsbury Park
Bradley Stoke
Bristol BS32 4QJ
Registered in England No.2858918
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you receive
this in error, please contact the sender and delete the material from any
computer.