Re: [PHP] green bean question on singleton php5
- From: eric.butera@xxxxxxxxx ("Eric Butera")
- Date: Wed, 16 Jan 2008 13:13:05 -0500
On Jan 16, 2008 12:57 PM, julian <correojulian33-php@xxxxxxxx> wrote:
Hi,
I am implementing this
class dbaccess{
static $db=null;
static $othervar=33;
private function dbaccess(){
dbaccess::$db= new mysqli("localhost",USER,PASSWD,DB);
if(mysqli_connect_errno()){
echo "no way";
}
}
public static function GetDb(){
if(dbaccess::$db==null){
dbaccess::$db= new dbaccess();
}
return dbaccess::$db;
}
}
$db=dbaccess::GetDE();
$db->query(..................);
will fail...with Call to undefined method dbaccess::query()
apparently $db is of type dbaccess... and thus has not does not have
query implemented....
any hhelp appreciated.....
JCG
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Try changing dbaccess to self inside the class.
Look at this:
http://us.php.net/manual/en/language.oop5.patterns.php
Example#2 Singleton Function
.
- Follow-Ups:
- Re: [PHP] green bean question on singleton php5
- From: Julian
- Re: [PHP] green bean question on singleton php5
- References:
- green bean question on singleton php5
- From: julian
- green bean question on singleton php5
- Prev by Date: Re: [PHP] Re: re[PHP] gister_globals
- Next by Date: RE: [PHP] (SOLVED) /etc/php.init changes not honored
- Previous by thread: green bean question on singleton php5
- Next by thread: Re: [PHP] green bean question on singleton php5
- Index(es):