RE: [PEAR-DEV] do pear packages create their own seperate DB connections?
| From: | Lukas Smith | Date: | Tue, 22 Apr 2003 13:16:15 +0000 |
| Subject: | RE: [PEAR-DEV] do pear packages create their own seperate DB connections? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-15325@lists.php.net to get a copy of this message | ||
> From: Jeroen Houben [mailto:jeroen@terena.nl]
> Sent: Tuesday, April 22, 2003 3:09 PM
> A lot of packages use DB (and in the future hopefully MDB) and they
all
> need a DSN as a constructor parameter. IMO it would be nice if
packages
> like Auth and Tree etc etc would also accept a reference to an
existing
> connection.
> Just to give you an example of how things can look right now (syntax
may
> not be completely correct)
> $conn = MDB::connect($dsn);
> $auth = new Auth('imap',array("dsn"=>$dsn));
> $tree = Tree::create('db', array("dsn"=>$dsn));
> $pm = new Auth_prefemanager(array("dsn"=>$dsn));
>
> These would all create seperate links and thus overhead, right? Or
does
> (M)DB already check for an existing connection and use that if it can?
> Jeroen
good idea.
The MDB_Manager has the possibility of getting an instance of MDB
instead of a dsn string or array. Generally with php4 the annoying bit
is that this has to be pass by reference which makes it in turn
impossible to make these parameters optional etc. But that should not be
a big deal as I assume these packages will always needs a dsn otherwise
anyways.
Aside form that the only method to handle the needless overhead a bit if
presistant connections. But it doesn't get rid of object instance
creation. Also if you use only one MDB instance you can make much better
use of its internal debugging mechanism because then you really see
which queries were made in what order (I bet nobody uses the debugging
functionality today .. if you are interested look in
MDB/tests/MDB_test.php towards the bottom)
Regards,
Lukas