Witam mam problem ze sterownikiem bazy danych, oto on:
<?
class DataBase {
public $connection;
public $database;
public $query;
public $result = array(); public $records = array(); public $queries = 0;
public $lastId;
private static $oInstance = false;
private function __construct(){}
public static function Instance
(){ if(self::$oInstance == false){
self::$oInstance = new DataBase();
}
return self::$oInstance;
}
public function error() {
}
public function connect($MYSQL_Host, $MYSQL_User, $MYSQL_Pass, $MYSQL_Base) {
if($MYSQL_Host && $MYSQL_User && $MYSQL_Pass && $MYSQL_Base){
$this->connection = mysql_pconnect($MYSQL_Host, $MYSQL_User, $MYSQL_Pass); if($this->connection){
if($this->database){
return TRUE;
} else {
return FALSE;
$this->error();
}
} else {
return FALSE;
$this->error();
}
}
}
public function close() {
if($this->connection){
unset($this->result, $this->database, $this->connection); return TRUE;
} else {
$this->error();
return FALSE;
}
}
public function query($query) {
if($query && $this->database){
if($this->result != ''){
$this->result = '';
}
$this->queries++;
return $this->result;
} else {
$this->error();
return FALSE;
}
}
public function fetch_array($arrayHandle=0) {
if($this->database && $this->result) {
if($arrayHandle==0){
return $this->records;
} else {
return $this->records;
}
} else {
$this->error();
}
}
public function fetch_row($rowHandle=0) {
if($this->database && $this->result) {
if($arrayHandle==0){
return $this->records;
} else {
return $this->records;
}
} else {
$this->error();
}
}
public function num_rows($resultHandle=0) {
if($arrayHandle==0){
return $num_rows;
} else {
return $num_rows;
}
}
}
?>
i próbuje sie odwołać w klasie do obsługi newsów w taki sposób:
<?php
class News{
public $DS;
/*
* Metoda konstrukcyjna z odniesieniem do źrodla danych
*/
public function __construct($DS){
$this->DS = $DS;
...
...
public function get_all($news_limit){
$news_all = $this->DS->query('SELECT * FROM cms_news ORDER BY news_id DESC LIMIT '.$news_limit);
return $news_all;
}
?>
wówczas wywala taki błąd:
Fatal error: Call to a member function query() on a non-object in C:\Program Files\WebServ\httpd\modules\News.php on line 34
plik index wygląd tak:
<?php
$DBase = DataBase::Instance(); //2
$DBase = $DBase->connect($MYSQL_Host, $MYSQL_User, $MYSQL_Pass, $MYSQL_Base);
//----------------------------------------------------
$News = new News($DBase);
?>
co może być przyczyną tego że nie widzi guery. oraz czy sterownik jest poprawnie napisany?