DB Connection parameters

From: Date: Tue, 16 Sep 2003 12:48:56 +0000
Subject: DB Connection parameters
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-21555@lists.php.net to get a copy of this message
There are several packages that take DB objects like: method($dbCon); I think what this is trying to allow is reuse of a db connection. First, you are not passing a reference, but a copy of the object. This means that you are not necessarily using the same connection ID as the orignal object, so the idea of passing the object around so a connection is not created for each query may or may not be working. In fact, if no connection was made usig the original object, a new one will be made each time it is passed. This is problematic for apps that create the object in the main app and pass it through a series of methods to produce the actual output. I think the desired behavor in most situations is: method(&$dbCon); The copied object will get the same connection id if the connection on the original object has already been made. But, I'm not sure how smart the db drivers are, but having multiple object accessing the same connection may be problematic. If this is a multithreaded application, then it will definitely be problematic as you will end up with thread contention. This also holds true in an event driven model. Also, a limitation of this is that the dbCon parameter is now required. So what I would suggest would be to create a method for setting the connection to use, then make the non reference parameter optional... The last thought is that with connection pooling, then a new object does not necessarily mean a new connection. The issue is that you either need to read to the end of the result set with autofree enabled, or call free() manually to allow the connection to be used by another process... Thoughts, comments, etc. Thanks, Rob

« previous php.pear.dev (#21555) next »