Re: Simple class declaration returns error [SOLVED]
| From: | Dave M G | Date: | Fri, 16 Jun 2006 12:54:42 +0000 |
| Subject: | Re: Simple class declaration returns error [SOLVED] | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-238159@lists.php.net to get a copy of this message | ||
Jochem,
Thank you for your advice. I was able to use your suggested code to develop the results I wanted.
I found I could simplify the "self" references down to just the name of the class.
The syntax I ended up with is
class database {
private static $database;
public static function getDB()
{
if (!isset($database))
$database = new database();
return $database;
}
private function __construct()
{
$this->dbConnect();
}
private function dbConnect()
{
// Database connection
return $result;
}
public function getData($type, $id)
{
// SQL Query
return $data;
}
And I call it like this:
$data = database::getDB()->getData($arg1, arg2);
Thank you for your time and advice.
--
Dave M G