[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-windows
Subject:    [PHP-WIN] var static
From:       80.224.65.87
Date:       2003-08-28 16:58:24
[Download RAW message or body]

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic