Re: green bean question on singleton php5
| From: | Julian | Date: | Wed, 16 Jan 2008 18:36:52 +0000 |
| Subject: | Re: green bean question on singleton php5 | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267424@lists.php.net to get a copy of this message | ||
but that forces me to implement a large interface of functions that I prefer to avoid...
the $dummy thing works... but I guess it is not "by the book".
I would like to understand what am I missing fom the concept....
Thanks.
JCG
Daniel Brown wrote:
On Jan 16, 2008 12:57 PM, julian <correojulian33-php@yahoo.es> wrote:Hi, I am implementing this[snip!]I'm heading out to lunch, so double-check this for errors, but Irewrote your class. You'll have to add your fetch handlers and such. <? class dbaccess{ static $db = null; static $conn = null; static $query = null; static $othervar = 33; private function self(){dbaccess::$conn = new mysqli(HOST,DBNAME,PASS,USERNAME); if(mysqli_connect_errno()){ return False; } else { return dbaccess::$conn; }} public function query($query){dbaccess::$query = mysqli_query(dbaccess::self(),$query); return dbaccess::$query;} public static function GetDb(){ if(dbaccess::$db==null){ dbaccess::$db= new dbaccess(); } return dbaccess::$db; } } $db=dbaccess::GetDb(); $db->query(......................); // Your query here. ?>