[PHP-WIN] var static

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

 



Hi!
I want to obtain only one instance of one class. In other to do that, I call
to a static method, that creates the instance(if it doesnt exit) or returns
the reference of the instance.
The call to the static method is the next:

   $conexiondb=db::getInstancia();

Well, but if I call to db::getInstancia() another time, I obtain another new
object  :-(

The code of the db class is the next (it is a Singleton Pattern, but it
doesnt work)

class db{
       var $_miInstancia;

       function db (){
          // funcion que se conecta con la BBDD
             static $miInstancia;
             $this->_miInstancia=&$miInstancia;

             $result = @mysql_pconnect("inforalv", "discoteca", "password");
             if (!$result)
               return false;
             if (!@mysql_select_db("discoteca"))
               return false;
       }

&function getInstancia(){
   if (!isset($this))
      $_miInstancia=new db();
   return $_miInstancia;
}
}

I think that the problem is that the var _miInstance is not static and I
dont know how to do it.
Could you please tell me if there is anything wrong?

Thanks.

Alvaro

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux