RE: [PEAR-DEV] DB Connection parameters

From: Date: Wed, 17 Sep 2003 14:19:22 +0000
Subject: RE: [PEAR-DEV] DB Connection parameters
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-21633@lists.php.net to get a copy of this message
Alan, > A few things to note.. > - remember that database connections are of type 'resource' > - resources are really just integers where the number points to an array > of id=>memory address > - hence passing them by referece doesnt make any difference.. (as the > number stays the same.. the zval only gets an extra refcount > temporarily... True if there has been a connection to the database established befor you pass the parameter. If there hasn't, then doing: $dbc = DB::connect($DSN); usedbobject1st($dbc); usedbobject2nd($dbc); usedbobject3rd($dbc); when the methods are defined as: usedbobject***($dbon) instead of: usedbobject***(&$dbcon) results in the creation of three different connections when the intent of the programmer was to pass the DB object around to use the same connection > > almost all the database drivers dont actually do any connections on > things like mysql_connect().. - if they are already connected.. - so the > reality is that you do not really need to share a connection for all the > uses of a db, however there are slight benefits in reduced overhead from > a global fetch of the db object, rather than going through the overhead > of working out how to connect.. Which is the point of creating it and passing it around, which is not happening in the example above. And the fact that the packages take the connection as a parameter for the constructor can be misleading, or even dangerous in the case of a multithreaded program. This is the stuff that leads to intermittent problems... > using & only make sense if you are going to modify the PHP variables of > an object.. - causing it to be copied..(in PHP4).. passing by reference > for Read only (or access to resorces etc) make no difference.. - as the > object is only refcounted.. But only if the reference already exists, which it does not if you create it at the top of your "main" program and then pass it through a series of functions like the example above... Thanks, Rob

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