Jump to content

ADOdb + singleton = undeclared static property


Loomy

Recommended Posts

I'm using ADOdb for my database backend, but I'm using it via my own [b]singleton[/b] database class. This is the most important parts of it:
[code]<?php
require_once('adodb/adodb.inc.php');

class DB
{
private static $instance;
private $adodb;


private function __construct()
{
$dsn = 'mysql://*********'':*******@**********?persist';
$adodb = NewADOConnection($dsn);

if(!$adodb) {
die("Could not connect");
}
}


public static function getInstance()
{
if(empty(self::$instance))
{
self::$instance = new DB();
}

return self::$instance;
}


// ...


public function select($sql)
{
return self::$adodb->Execute($sql);
}

[/CODE]

And the code to test if it's working:

[CODE]<?php

require_once('database/DB.class.php');

$db = DB::getInstance();


$rs = $db->select('SELECT * FROM `user_level`');
echo $rs->_numOfFields;

?>[/CODE]


Error message:
Fatal error: Access to undeclared static property: DB::$adodb in (...)DB.class.php on line 66

Line 66 is the one with [i]return self::$adodb->Execute($sql);[/i] in select()


Any ideas how I can fix this? And what's wrong?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.