[nycphp-talk] OO & database connections
Daniel Convissor
danielc at analysisandsolutions.com
Thu Jul 15 15:41:50 EDT 2004
Hi Jeff and David:
On Thu, Jul 15, 2004 at 02:53:42PM -0400, David Sklar wrote:
>
> The performance optimization is:
> Assuming the different databases are on the same server, create one
> connection and then pass that around in your program.
...
> The encapsulation and object re-use optimization is:
> Have each object connect separately with its own credentials, allowing
> you freedom in the future to move the databases to different servers,
> tweak access control from each object, etc.
You can put the two ideas together. Have each class extend it's database
connection from a common database class. When instantiating, do a check
to see if a database connection already exists with the given criteria.
If so, use the existing connection object. If not, create a new
connection object. A singleton method may be what you're looking for.
Hmm, but isn't that kind of what PHP does automatically?
"If a second call is made to mysql_connect() with the same arguments, no
new link will be established, but instead, the link identifier of the
already opened link will be returned."
-- http://us3.php.net/mysql_connect
Not sure of the performance implications of trying multiple connects with
the same credentials. If PHP does it without contacting the datbase
server, it may be about the same speed as doing your own checks. I'm to
busy right now to try some tests.
See you,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list