Witam!
mam mały problem:
Otórz mam kontroler bazy danych, i gdy stosuje taki oto kod :
<?php
$result = $News->get_all();
if ($DBase->num_rows($result) > 0) {
while ($record = $DBase->fetch_row()) { // tutaj błąd bo gdy zastosować mysql_fetch_row wszystko gra
$outputNews = new Templates('./templates/news.tpl');
$outputNewsValues = array("news_date" => $record['news_date'], "news_subject" => $record['news_subject'],
"news_text" => $record['news_text'],
"news_author" => $record['news_author']);
$outputNews->save($outputNewsValues);
$center .= $outputNews->parse();
}
$center .= '<div align="right"><a href="">archiwum</a> »</div>';
} else {
$center = 'brak newsow w bazie';
}
?>
to wyświetla mi się pusty błąd("0:" - na górze strony), i momo tego bugu newsy chodzą
klasa kontrolera:
<?php
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) {
$this->result = ($arrayHandle==0) ? $this->result : $arrayHandle;
if($this->database && $this->result) {
// if(is_array($this->records)){
return $this->records;
// } else {
// $this->error(); // przez to właśnie pojawia sie ten błąd
// }
} else {
$this->error();
}
}
public function fetch_row($rowHandle=0) {
$this->result = ($rowHandle==0) ? $this->result : $rowHandle;
if($this->database && $this->result) {
// if($this->records){
return $this->records;
// } else {
// $this->error(); // przez to właśnie pojawia sie ten błąd
// }
} else {
$this->error();
}
}
public function num_rows($resultHandle=0) {
$this->result = ($resultHandle==0) ? $this->result : $resultHandle;
return $num_rows;
} else {
$this->error();
}
}
}
?>
Ten post edytował raf2001 6.05.2006, 14:41:34