Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Problema strano con class extends

    Ho un problema stranissimo, adesso vi elenco un momento tutte le parti del codice:
    [CLASSE MYSQL]
    Codice PHP:
    class db_driver
    {
        var 
    $dbInfo = array (
          
    "sql_host"  =>  "localhost",
          
    "sql_name"  =>  "",
          
    "sql_user"  =>  "root",
          
    "sql_pass"  =>  "",
          
    "sql_type"  =>  "mysql",
          
    "sql_port"  =>  "",
          
    "tbl_prefix"    =>  "fmp_"
          
    );

      
    // > Creaiamo la funzione che ci passerà tutt le var
     /*function MySQL ($dbhost, $dbuser, $dbpass, $dbname)
     {

      $this->host = (string)   $dbhost;
      $this->dbuser = (string) $dbuser;
      $this->dbpass = (string) $dbpass;
      $this->dbname = (string) $dbname;
      $this->is_error = FALSE;
      $this->msg_error = '';  

     //return is_resource( $this->Connect() ) ? $this->Connect() : null;
     
    }*/

    //> Creiamo la funzione per connetterci
        
    function Connect()
        {
      
    // > Connessione secondo i parametri passatoci da host,fbuser e dbpass
      
    $this->conn mysql_connect($this->dbInfo['sql_host'],
              
    $this->dbInfo['sql_user'],
                
    $this->dbInfo['sql_pass']
            );
          
    // > Faccimo un if per controllare se la connessione e avvenuta
            // > Se $this-> restituisce (is_resource) (TRUE)
        
    if( is_resource($this->conn) )
          {  
          
    // > ... 
            // >  Selezioniamo il db
        
    $this->selectdb mysql_select_db(
                    
    $this->dbInfo['sql_name'] ,
                  
    $this->conn
                  
    );
          
    // > Controlliamo che il select_db sa avvenuto
          
    if (! $this->selectdb)
        {
         
    // > Se ci sono errori settiamo la var a True
            
    $this->is_error TRUE;
            
    // > e settiamo la variabile col tipo di errore
            
    $this->error_type 2;
            
    $this->db_error_msg $this->dbInfo['sql_name']."not exists";
      
          }   
     
          }  
      
    // > altrimenti
      
    else
          {
          
    //Settiamo gli errori
        // > Errore = True (Vero)
        
    $this->is_error TRUE;
        
    // > e settiamo la variabile col tipo di errore
        
    $this->error_type 1;
        
    $this->db_error_msg mysql_error();
            return(
    0);
          }  
            
    // > effetuiamo il return di $this->conn
        
    return $this->conn;
        return 
    $this->selectdb;

        }

      
        
    // > Creaiamo la funzione per la query
        
    function query($query NULL)
        {
      
    // > Settiamo il valore della query
      
    $this->query = (string) $query;
      
    $this->Connect();
       
    // > Controlliamo ancora una volta se la connessione è effetuata
       
    if ( is_resource$this->Connect() ) )
        {  
          
    // > Se al connessione e effettuata, Lanciamo la query
          
    $this->query mysql_query($this->query,$this->Connect());
         
    // > Controlliamo se la query e avvenuta
            
    if (! is_resource($this->query))
            {
         
    // > Se ci sono errori settiamo la var a True
            
    $this->is_error TRUE;
            
    // > e settiamo la variabile col tipo di errore
            
    $this->error_type 3;
            
    $this->db_error_msg mysql_error();
        }   
          }
          
    // > Ritorniamo all'if della connessione prima di effetuare la query
         // > se la query nn è avvenuta
      
    else
          {
       
    // > setta l'errore a TRUE
        
    $this->is_error TRUE;
        
    // > e settiamo la variabile col tipo di errore
        
    $this->error_type 1;
        
    $this->db_error_msg mysql_error();
        }  
        
    // > Mostriamo la query
            
    return $this->query;
        
        }
        
    // > Funzione per il fetch_array
        
    function fetcharray($fetcharray NULL)
        {
       
    // > controlliamo se al moemnto del lancio del fetcharray
        // > puo essere lanciato
        
      
    if (!is_resource($fetcharray)) 
      {
                
    // > Se no ...
            // > Settiamo l'errore a TRUE
         
    $this->is_error TRUE;
         
    // > e settiamo la variabile col tipo di errore
            
    $this->error_type 4;
        
    $this->db_error_msg mysql_error();
         return 
    FALSE;
           }
              
    // >Diciariamo la var fetcharray con il suo contenuto
              
    $this->fetcharray $fetcharray;

              
    // > Facciamo il solito controllo sulla connessione  
       
    if ( is_resource$this->Connect() ) )
       {  
              
    // > Se la connessione e avvenuta, allora facciamo il fetcharray  
        
    $this->fetcharray mysql_fetch_array($this->fetcharray);
            
    // > Controlliamo se il fetcharray e stato effettuato con successo
        
    if (! is_resource($this->fetcharray))
       {
        
    // > Se no, settiamo l'errore a True
        
    $this->is_error TRUE;
        
    // > e settiamo la variabile col tipo di errore
        
    $this->error_type 4;
        
    $this->db_error_msg mysql_error();
      }   
      }
      
    // > Se la connessione nn è avvenuta
          // > allora...
      
    else
      {
          
    // > Settami l'errore a True
         
    $this->is_error TRUE;
         
    // > e settiamo la variabile col tipo di errore
         
    $this->error_type 1;
         
    $this->db_error_msg mysql_error();
      }  
         
    // > Mostriamo la var di getcharray 
        
    return $this->fetcharray;
        
        }
            
    // > Funzione per la chiusura della connessione
              // > Dichiariamo la funzione close 
        
    function close () 
        {
      
    // > Facciamo il solito controllo sulla connessione
      
    if ( is_resource$this->Connect() ) )
          {    
             
    // > se la connessione e avvenuta, Chiudiamola
            
    $this->dbclose mysql_close($this->Connect());     
             
    // > altrimenti
        // > Se la connessione non è avvenuta
            
    }
      else
      {
       
    // > setta l'errore a TRUE
        
    $this->is_error TRUE;
        
    // > e settiamo la variabile col tipo di errore
        
    $this->error_type 1;
        
    $this->db_error_msg mysql_error();
      }
      return 
    $this->dbclose;
        }
        function 
    db_error()
        {
            switch(
    $this->error_type)
      {
            
          case 
    1
        die (
    "<html>\n<head>\n<title>Portal Error</title>\n</head>\n<body>\n<font face=verdana size=1.5>[b]DB_ERROR:[/b]
    \nConnessione fallita/Connection Failed:
    <font color=red>[b]\n"
    .$this->db_error_msg."[/b]</font></font>\n</body>\n</html>");
          break;
      
          case 
    2
              die (
    "<html>\n<head>\n<title>Portal Error</title>\n</head>\n<body>\n<font face=verdana size=1.5>[b]DB_ERROR:[/b]
    \nSelezione del database Fallita/Database selection Failed: 
    \n<font color=red>[b]"
    .$this->db_error_msg."[/b]</font></font>\n</body>\n</html>");
          break;
          
          case 
    3:  
              die (
    "<html>\n<head>\n<title>Portal Error</title>\n</head>\n<body>\n<font face=verdana size=1.5>[b]DB_ERROR:[/b]
    \nQuery Fallita/Failed Query: 
    \n<font color=red>[b]"
    .$this->db_error_msg."[/b]</font></font>\n</body>\n</html>");
          break;
      
          default:
        
    $this->error 'N';
          break;
      }
        }
      
    }
    ?> 
    [INDEX FILE]
    Codice PHP:
    // > Set Path
    define('SYSTEM_FOLDER',"System");
    define ('DRIVERS_FOLDER',SYSTEM_FOLDER.'/driver/');

    // > Definizione degli errori degli errori

    //error_reporting  (E_ERROR | E_WARNING | E_PARSE);
    define ('GLOBAL_ERROR',0);

    // > Definizione dei componenti di default

    define ('STARTING_MODULES',"");
    define ('STARTIND_SYSTEM',1);

    // > Require global configuration file

    require("config.php");

    //===========================================================================
    // DEBUG CLASS
    //===========================================================================
    class Debug
    {
       var 
    $starttime;
       var 
    $totaltime;
        
        function 
    sTIMER()
        {
            
    $gtimer microtime ();
            
    $gtimer explode (' '$gtimer);
            
    $gtimer $gtimer[1] + $gtimer[0];
      
    $gtimer $gtimer/1000000;
            
    $this->starttime $gtimer;
        }
        function 
    eTIMER()
        {
            
            
    $gtimer microtime ();
            
    $gtimer explode (' '$gtimer);
            
    $gtimer $gtimer[1] + $gtimer[0];
            
    $endtime $gtimer;
            
    $totaltime round (($endtime $this->starttime), 5);
            return 
    $totaltime;
        }
    }

    class 
    information
    {
        var 
    $version          =          "0.9";
    }

    require 
    DRIVERS_FOLDER."class.db_driver.php";
    $DBS = new db_driver();

    // > Settiamo l'array $dbInfo della classe db_drive per la configurazione

    $DBS->dbInfo['sql_type']  =  $DB['type'];
    $DBS->dbInfo['sql_host']  =  $DB['host'];
    $DBS->dbInfo['sql_user']  =  $DB['user'];
    $DBS->dbInfo['sql_pass']  =  $DB['pass'];
    $DBS->dbInfo['sql_name']  =  $DB['name'];
    $DBS->dbInfo['sql_host']  =  $DB['host'];
    $DBS->dbInfo['tbl_prefix']  =  $DB['tbl_prefix'];

    // Verifichiamo la presenza di errori nella connessione
     // se vi sono errori con un die interrompiamo lo script
     
     
    $DBS->db_error();
     
    //===========================================================================
    // Template Class
    //===========================================================================

    require (SYSTEM_FOLDER."/db_template.class.php");
    $PROVA = new db_template();
    $PROVA->tpl_load(); 
    [db_template.php (CLASSE CON PROBLEMA)]
    Codice PHP:
    class db_template extends db_driver
    {

        var 
    $templateInfo = array (
              
    "tpl_id"   => '',
              
    "tpl_name" => ''
             
    );
             
        function 
    tpl_load() 
        {
         echo 
    "<pre>";print_r($this);
      
    $this->query("SELECT * from fmp_template_skin");
      
    $this->db_error();
        }

    Il problema sta che nell'ultima classe quella del tempate (funzione tpl_load()) qiando lancio la query se sbaglio il nome della tabella mi esce


    db_template Object
    (
    [dbInfo] => Array
    (
    [sql_host] => localhost
    [sql_name] =>
    [sql_user] => root
    [sql_pass] =>
    [sql_type] => mysql
    [sql_port] =>
    [tbl_prefix] => fmp_
    )

    [templateInfo] => Array
    (
    [tpl_id] =>
    [tpl_name] =>
    )

    )





    DB_ERROR:
    Query Fallita/Failed Query:
    Table 'frontmedia.fmdp_template_skin' doesn't exist
    Se la metto giusto mi dice che nn ho selezionato il db

    [QUOTE]
    db_template Object
    (
    [dbInfo] => Array
    (
    [sql_host] => localhost
    [sql_name] =>
    [sql_user] => root
    [sql_pass] =>
    [sql_type] => mysql
    [sql_port] =>
    [tbl_prefix] => fmp_
    )

    [templateInfo] => Array
    (
    [tpl_id] =>
    [tpl_name] =>
    )

    )





    DB_ERROR:
    Selezione del database Fallita/Database selection Failed:
    not exists




    se la lancio nel file di root (index.php) dopo aver lanciato la classe invece funge:
    Codice PHP:
    require DRIVERS_FOLDER."class.db_driver.php";
    $DBS = new db_driver();

    // > Settiamo l'array $dbInfo della classe db_drive per la configurazione

    $DBS->dbInfo['sql_type']  =  $DB['type'];
    $DBS->dbInfo['sql_host']  =  $DB['host'];
    $DBS->dbInfo['sql_user']  =  $DB['user'];
    $DBS->dbInfo['sql_pass']  =  $DB['pass'];
    $DBS->dbInfo['sql_name']  =  $DB['name'];
    $DBS->dbInfo['sql_host']  =  $DB['host'];
    $DBS->dbInfo['tbl_prefix']  =  $DB['tbl_prefix'];

    $DBS->query("...");

    // Verifichiamo la presenza di errori nella connessione
     // se vi sono errori con un die interrompiamo lo script
     
     
    $DBS->db_error(); 
    perke questo ?
    Chiamatemi sven se volete non ho voglia di fare una nuova email per una nuova registrazione xD
    Mac Future User , Ventilatore for PC Cooler user , - dry is coming -

  2. #2
    up :quote:
    Chiamatemi sven se volete non ho voglia di fare una nuova email per una nuova registrazione xD
    Mac Future User , Ventilatore for PC Cooler user , - dry is coming -

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.