Re: Testing for instance of pear DB.

From: Date: Tue, 16 Apr 2002 21:46:46 +0000
Subject: Re: Testing for instance of pear DB.
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1149@lists.php.net to get a copy of this message
There is currently no rock solid way, because they all depend on implementation details, but here's a suggestion: if (is_object($obj) && get_parent_class($obj) == 'db_common' && method_exists($obj, 'simpleQuery')) { } I'll add a DB::isConnection() method so you can use that instead. - Stig On Tue, 2002-04-16 at 23:46, destr0 wrote: > I have a script that passes an instance of pear DB to several different > objects so they can use it internally to make queries. I'd like to set up > my objects so that they test whether or not they have been passed an actual > instance of pear's DB class and if not, then I want them to create one > internally. > > class someObj > { > //properties > var $DB; > > //constructor > function someObj($passedResource) > { > if(test for whether or not the object is a pear DB resource) > $this->DB = $passedResource; > else > $this->DB = DB::Connect($someDsn); > } > } > > The problem I have is how to test whether or not the passedResource is a > pear DB object. If i use get_class() it returns "db_mysql". The problem > with that is that if I start testing against "db_mysql" then the script is > no longer database independant because if I switch databases, then the > object will, I assume, be derived from a different class. > > So I need a solid way to test whether a variable is an instance of a pear DB > connection object. > > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.general (#1149) next »