Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Mały problem z errorem kontrolera bazy mysql
Forum PHP.pl > Forum > Przedszkole
raf2001
Witam!
mam mały problem:
Otórz mam kontroler bazy danych, i gdy stosuje taki oto kod :
  1. <?php
  2.  $result = $News->get_all();
  3.    if ($DBase->num_rows($result) > 0) {
  4.      while ($record = $DBase->fetch_row()) { // tutaj błąd bo gdy zastosować mysql_fetch_row wszystko gra
  5.        $outputNews = new Templates('./templates/news.tpl');
  6.        $outputNewsValues = array("news_date" => $record['news_date'],
  7.                                  "news_subject" => $record['news_subject'],
  8.                                  "news_text" => $record['news_text'],
  9.                                  "news_author" => $record['news_author']);
  10.        $outputNews->save($outputNewsValues);
  11.        $center .= $outputNews->parse();
  12.      }
  13.      $center .= '<div align="right"><a href="">archiwum</a> &raquo;</div>';
  14.    } else {
  15.      $center = 'brak newsow w bazie';
  16.    }
  17. ?>

to wyświetla mi się pusty błąd("0:" - na górze strony), i momo tego bugu newsy chodzą
klasa kontrolera:
  1. <?php
  2. class DataBase {
  3.    public $connection; 
  4.    public $database; 
  5.    public $query; 
  6.    public $result = array(); 
  7.    public $records = array(); 
  8.    public $queries = 0; 
  9.    public $lastId; 
  10.    
  11.    private static $oInstance = false;
  12.  
  13.    private function __construct(){}
  14.  
  15.    public static function Instance(){
  16.      if(self::$oInstance == false){
  17.        self::$oInstance = new DataBase();
  18.      }
  19.      return self::$oInstance;
  20.    }
  21.    
  22.    public function error() { 
  23.      echo '<b>'.mysql_errno().'</b> : '.mysql_error().'<br>'; 
  24.    } 
  25.    
  26.    public function connect($MYSQL_Host, $MYSQL_User, $MYSQL_Pass, $MYSQL_Base) { 
  27.      if($MYSQL_Host && $MYSQL_User && $MYSQL_Pass && $MYSQL_Base){
  28.        $this->connection = mysql_pconnect($MYSQL_Host, $MYSQL_User, $MYSQL_Pass);
  29.            if($this->connection){
  30.                     $this->database = mysql_select_db($MYSQL_Base);
  31.            if($this->database){
  32.                  return TRUE;
  33.            } else {
  34.                  return FALSE;
  35.                  $this->error();
  36.                  mysql_close($this->connection);
  37.            }
  38.        } else {
  39.            return FALSE;
  40.            $this->error();
  41.        }     
  42.      } 
  43.    } 
  44.  
  45.    public function close() {
  46.             if($this->connection){
  47.            mysql_close($this->connection);
  48.        unset($this->result, $this->database, $this->connection);
  49.        return TRUE;
  50.      } else {
  51.        $this->error();
  52.        return FALSE;
  53.      }          
  54.    } 
  55.  
  56.    public function query($query) { 
  57.      if($query != '' && $this->database){
  58.        if($this->result != ''){
  59.          $this->result = '';
  60.        }
  61.        $this->result = mysql_query($query);
  62.        $this->lastId = mysql_insert_id();
  63.        $this->queries++;
  64.        return $this->result;
  65.      } else {
  66.        $this->error();
  67.        return FALSE;
  68.      }
  69.    } 
  70.  
  71.    public function fetch_array($arrayHandle=0) { 
  72.             $this->result = ($arrayHandle==0) ? $this->result : $arrayHandle; 
  73.      if($this->database && $this->result) { 
  74.        $this->records = mysql_fetch_array($this->result, MYSQL_ASSOC); 
  75.     //   if(is_array($this->records)){
  76.                     return $this->records;
  77.         //   } else {
  78.         //           $this->error(); // przez to właśnie pojawia sie ten błąd
  79.         //  }            
  80.      } else {
  81.            $this->error(); 
  82.      }
  83.    } 
  84.  
  85.    public function fetch_row($rowHandle=0) { 
  86.             $this->result = ($rowHandle==0) ? $this->result : $rowHandle; 
  87.      if($this->database && $this->result) { 
  88.        $this->records = mysql_fetch_array($this->result, MYSQL_ASSOC); 
  89.     //   if($this->records){
  90.                     return $this->records;
  91.         //   } else {
  92.         //           $this->error();  // przez to właśnie pojawia sie ten błąd
  93.         //   }            
  94.      } else {
  95.            $this->error(); 
  96.      }    
  97.    } 
  98.  
  99.    public function num_rows($resultHandle=0) { 
  100.      $this->result = ($resultHandle==0) ? $this->result : $resultHandle; 
  101.      if($num_rows = mysql_num_rows($this->result)){
  102.            return $num_rows;
  103.          } else {
  104.            $this->error(); 
  105.          }
  106.    } 
  107.  }
  108.  
  109. ?>
Master Miko
function.mysql-errno.php" title="Zobacz w manualu php" target="_manual

Cytat
Zwraca numer błędu ostatnio wywołanej funkcji MySQL, lub Returns the error number from the last MySQL function, or 0 (zero) jeśli żaden błąd nie wystąpił.


Proponuję czytać Emanuela smile.gif
raf2001
tak tylko czemu wyświetla ten błąd, ponieważ dane są pobierane(bez $this->records wyniku by niebyło,a błąd się wyświetla). A chodzi mi oto aby zachować mniej więcej składnie tego fech_row/array ale żeby niebyło tego błędu.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.