Class PHP4 problem

From: Date: Wed, 29 Sep 2004 15:08:49 +0000
Subject: Class PHP4 problem
Groups: php.general 
Request: Send a blank email to php-general+get-198196@lists.php.net to get a copy of this message
<?php //db_class.php error_reporting(E_ALL); class Db_Connect { var $host; var $user; var $pasw; var $MYSQL_ERRNO; var $MYSQL_ERROR; var $query; function make_connect($host, $user, $pasw) {
      $this->host = $host;
      $this->user = $user;
      $this->pasw = $pasw;
      $link_id = mysql_connect($this->host, $this->user, $this->pasw);
      if (!$link_id) {
       die("Impossibile connettersi al server mysql " . "<br>" .
           "Dettagli: " . $this->MYSQL_ERROR . "Errore No: " . $this->MYSQL_ERRNO);
      }
      else {
       return $link_id;
      }
} function select_db($db_name) {
      if (!(mysql_select_db($db_name))) {
               die("Impossibile selezionare il database " . $db_name . "<br>" .
                   "Dettagli: " . $this->MYSQL_ERROR . "<br>" . "Errore No: " . $this->MYSQL_ERRNO);
                   }
} function sql_query($query) {
      if (!(mysql_query($query))) {
             die("Impossibile eseguire query al database " . "<br>" .
                 "Dettagli: " . $this->MYSQL_ERROR . "<br>" . "Errore No: " . $this->MYSQL_ERRNO);
                 }
      else $result = mysql_query($query);
      return $result;
} function close_connection() {
       mysql_close($this->make_connect());
} } class Result_Db extends Db_Connect {
     function get_data() {
         $res = $this->sql_query($query);
         while($db_data = mysql_fetch_array($res)) {
               echo $db_data["tot"] . "<br>";
         }
     }
} $obj = new Result_Db; $obj->make_connect('localhost', 'root', ''); $obj->select_db('sottilelinearossa'); $obj->sql_query('select count(id) as tot from articoli'); $obj->get_data(); ?> I get this message because the variable is not valid when call the method sql_query in the child class Result_Db. How to fix this problem ? Notice: Undefined variable: query in c:\programmi\apache group\apache\users\kioto\db_class2.php on line 66 Impossibile eseguire query al database Dettagli: Errore No:

« previous php.general (#198196) next »