RE: green bean question on singleton php5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Julian [mailto:julcol33@xxxxxxxx]
> Sent: Wednesday, January 16, 2008 3:37 PM
> To: Daniel Brown
> Cc: julian; php-general@xxxxxxxxxxxxx
> Subject: Re:  green bean question on singleton php5
> 
> 
> 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@xxxxxxxx> wrote:
> >
> >> Hi,
> >>
> >> I am implementing this
> >>
> > [snip!]
> >
> >     I'm heading out to lunch, so double-check this for errors, but I
> > rewrote 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.
> > ?>
> >
> >

dbaccess has no "query" method as you are not inheriting from mysqli. So
dbaccess::$db will have no query method either. I don't even think you need
to construct objects of type "dbaccess" to make this work, after all, you
have only static methods and properties which are attached to the type and
not the instances. Also, dbaccess::$db should be mysqli::db instead.

Check the previous suggestions about creating either an inherited class, or
an accessor.

Regards,

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695
Email: info@xxxxxxxxxxxxx  | MSN Chat: best@xxxxxxxxxxxxx  |  SKYPE:
bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-diy.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux