note 35277 added to language.oop
| From: | inforalv at wanadoo dot es | Date: | Tue, 26 Aug 2003 11:57:04 +0000 |
| Subject: | note 35277 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55097@lists.php.net to get a copy of this message | ||
I have written this code:
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;
}
}
This is a Singleton Pattern, but it doesnt work.
I want to obtain only one instance of db class but when I do this...:
$conexiondb=db::getInstancia();
$conexiondb=db::getInstancia();
In the two calls I get a new db object.
Could you please tell me if there is anything wrong?
Thanks.
alvaro
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35277
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35277&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35277&report=yes