TobiasBuschi: PHP5 Klassenvariable

Beitrag lesen

Ich hoffe du findest dich im Code zurecht.
Es gibt keine Fehlermeldung, aber es kommt 2 mal "halllllloooo" auf den Bildschirm, das heist die Struktur der DB wird in der Funktion "get_dbStruct" zwei mal ermittelt.

Ich dachte eigentlich (du wahrscheindlich auch), dass die statisch deklarierte Variable $dbStruct in der abgeleiteten Klasse auch noch mit dem Initialisierten Wert von der rpDBM Klasse vorzufinden ist, dem ist leider nicht so, sie hat wieder den Wert "null" :(

  
// Datenbank-Management  
class rpDBM{  
 private static $dbStruct = null;  
 private static $dbRels   = null;  
  
 public function get_dbStruct(){ // tabellen/felder  
  if( is_null($this->dbStruct) ){  
   return $this->init_dbStruct();  
  }  
  return $this->dbRels;  
 }  
 public function get_dbRels(){ // beziehungen  
  if( is_null($this->dbRels) ){  
   return $this->init_dbRels();  
  }  
  return $this->dbRels;  
 }  
  
 function connect(){  
  if( $this->dbConnect = mysql_connect('localhost','root','') AND $this->dbSelected = mysql_select_db(rpdbm) ){  
   if( @mysql_query("SELECT version FROM rpa_info WHERE id = '1'") ){ // Datenbank kompatibel?  
    $return = true;  
   } else {  
    $return = false;  
   }  
  } else {  
   $return = false;  
  }  
  
  if($return){  
   $this->get_dbStruct(); // 1. Aufruf  !!!!!!!!  
   $this->get_dbRels();  
  } else {  
  }  
  return $return;  
 }  
  
 private function init_dbStruct(){  
   echo "halllllllllo";  
   $e_res = mysql_list_tables('rpdbm');  
   while($e = mysql_fetch_row($e_res)){  
    $e_n = $e[0];  
  
    $a_res=mysql_query("SHOW FIELDS FROM `$e_n`");  
    while($a = mysql_fetch_array($a_res, 1)){  
     $a_n = $a['Field'];  
  
     $struct["$e_n"]["$a_n"] = $a;  
    }  
   }  
   $this->dbStruct = $struct;  
   return $struct;  
 }  
 private function init_dbRels(){  
   $query = "  
   SELECT  
   e0.id  AS `id`, e0.entity  AS `from_e` , e0.field  AS `from_a` ,  e0.typ  AS `typ`, e0.del_cas AS `del_cas`, e0.clone_cas AS `clone_cas`,  
   e53.id AS `r_id`, e53.entity AS `e`, e53.field AS `a`,  e53.typ AS `r_typ`  
   FROM  
   `rpa_relations` AS e0  ,`rpa_relations` AS e53  
   WHERE  
   e53.id    = e0.relation_id  
   ";  
  
   $rel_res = mysql_query($query);  
   while ( $db_rels = mysql_fetch_array($rel_res, 1) ){  
    $id = $db_rels['id'];  
    $e  = $db_rels['from_e'];  
    $a  = $db_rels['from_a'];  
  
    unset($db_rels['id']);  
    unset($db_rels['from_e']);  
    unset($db_rels['from_a']);  
    unset($db_rels['log_id']);  
    unset($db_rels['log_id_ch']);  
  
    $rels["$e"]["$a"]["$id"] = $db_rels;  
   }  
   $this->dbRels = $rels;  
   return $rels;  
 }  
}  
  
class rpDBM_relations extends rpDBM{  
 public function checkNoField($display = true){  
  $struct = $this->get_dbStruct(); // 2. Aufruf !!!!!!  
  foreach($struct AS $table => $fields){  
   foreach($fields AS $field => $f_opt){  
  
   }  
  }  
 }  
}  
  
$dbm = new rpDBM;  
$dbm->connect();  
  
$test_rel_check = new rpDBM_relations;  
$test_rel_check->checkNoField();