Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802

    datagrid e ristrutturazione della classe di connessione

    salve ragazzi , ho scaricato una classe per il datagrid , adesso succede che ,dovrei adattare la classe alle mie esigenze , che sarebbero modificare la connessione interna al database questa e l originale ,
    Codice PHP:
        private function getDataHTML()
        {
            
    $tmpHTML "";

            
    $db = new flor_db_process();
            
    $db->resultSet $this->resultSet;
            
    $db->reset();
            
            
    $gridHeaderComplete false;
            if (!
    $gridHeaderComplete)
            {
                
    $tmpHTML $this->getHeaderHTML();
                
                
    $gridHeaderComplete true;
            }
            
            if (
    $this->resultSet)
            {
                
    $this->rowCount $this->resultSet->num_rows;

                if (
    $this->rowCount==0)
                    
    $tmpHTML .= $this->getTableHTML("NODATA");
                else
                {
                    while(
    $tmpRow $db->getRow2())
                    {
                        
    $this->curRowId++;
                        
                        if (
    $this->pageByName)
                        {
                            
    $tmpCellVal $tmpRow[$this->pageByName_field];
                            if (!
    $tmpCellVal)
                                continue;        
    //skip row
                            
                            
    $tmpStr1 strtoupper(substr($tmpCellVal,0,1));
                    
                            if (
    is_numeric($tmpStr1) && $this->curPgAlphaIndex == "0-9")
                            {
                                
    //is numeric value
                            
    }
                            elseif (
    $tmpStr1 != strtoupper($this->curPgAlphaIndex))
                                continue;    
    //skip row    

                        
    }
                        elseif(
    $this->paging)
                        {
                            if (
    $this->curPgIndex == 1)
                                
    $lowRowID 0;
                            else
                                
    $lowRowID = (($this->curPgIndex-1) * $this->paging_NoOfRows)+1;
                            
    $hiRowID $this->curPgIndex $this->paging_NoOfRows;

                            if (
    $this->curRowId >= $lowRowID &&
                                
    $this->curRowId <= $hiRowID)
                            {
                                
    //allow row.. it belongs to page 
                            
    }     
                            else
                                continue;    
    //skip row.
                        
    }
                        
                        
    $tmpHTML .= $this->getDataRowHTML($tmpRow);
                    }
                }
            }
            else
                
    $tmpHTML .= $this->getTableHTML("NODATA");
            
            
            
    //echo "*".$this->rowCount."*".$this->columnCount."*";
            //print_r($this->colInfo);
            
            
    return $tmpHTML;
        } 
    e qui e quella che ho modificato :

    Codice PHP:
        private function getDataHTML()
        {
            
    $tmpHTML "";

            
    $dbcore = new DB();
            
    $dbcore->getnumrows $this->resultSet;
            
            echo 
    '<pre>';
            
    print_r($dbcore );
            echo 
    '</pre>';

            
    $gridHeaderComplete false;
            if (!
    $gridHeaderComplete)
            {
                
    $tmpHTML $this->getHeaderHTML();
                
                
    $gridHeaderComplete true;
            }
            
            if (
    $this->resultSet)
            {
                
    $this->rowCount $this->resultSet->num_rows;

                if (
    $this->rowCount==0)
                    
    $tmpHTML .= $this->getTableHTML("NODATA");
                else
                {
                    while(
    $tmpRow $dbcore->getlist())
                    {
                        
    $this->curRowId++;
                        
                        if (
    $this->pageByName)
                        {
                            
    $tmpCellVal $tmpRow[$this->pageByName_field];
                            if (!
    $tmpCellVal)
                                continue;        
    //skip row
                            
                            
    $tmpStr1 strtoupper(substr($tmpCellVal,0,1));
                    
                            if (
    is_numeric($tmpStr1) && $this->curPgAlphaIndex == "0-9")
                            {
                                
    //is numeric value
                            
    }
                            elseif (
    $tmpStr1 != strtoupper($this->curPgAlphaIndex))
                                continue;    
    //skip row    

                        
    }
                        elseif(
    $this->paging)
                        {
                            if (
    $this->curPgIndex == 1)
                                
    $lowRowID 0;
                            else
                                
    $lowRowID = (($this->curPgIndex-1) * $this->paging_NoOfRows)+1;
                            
    $hiRowID $this->curPgIndex $this->paging_NoOfRows;

                            if (
    $this->curRowId >= $lowRowID &&
                                
    $this->curRowId <= $hiRowID)
                            {
                                
    //allow row.. it belongs to page 
                            
    }     
                            else
                                continue;    
    //skip row.
                        
    }
                        
                        
    $tmpHTML .= $this->getDataRowHTML($tmpRow);
                    }
                }
            }
            else
                
    $tmpHTML .= $this->getTableHTML("NODATA");
            
            
            
    //echo "*".$this->rowCount."*".$this->columnCount."*";
            //print_r($this->colInfo);
            
            
    return $tmpHTML;
        } 
    ho fatto un print_r(); della mia classe , e mi da questo
    codice:
    DB Object
    (
        [dbcore] => 
        [host] => localhost
        [user] => root
        [pass] => maurizio
        [name] => vx
        [getnumrows] => Array
            (
                [Id] => 8
                [FirstName] => Chris
                [LastName] => Rich
                [BirthDate] => 2003-09-03
                [Gender] => f
                [Done] => 33
            )
    
    )
    pero non fa il calcolo perche mi potreste dare una mano grazie mille
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    ci sono due database e vogli per inviare l'informazione a entrambi? se cosi poi deve si cambiare flor_db_process().

    Mi spiego:
    Codice PHP:
    <?php
    // usi il principale database per $host='...',$nome='...',ecc.
    function flor_db_process($host='localhost',$nome='LOGIN',$pass='PASSWORD',$db='DATABASE'){
      
    mysql_connect($host,$nome,$pass);
      
    mysql_select_db($db);
    }
    ?>
    desidero che ti ho aiutato!

    Ciao,
    Dennis
    Nuovo Blog di Programmazione! (Lo ha i tutti tipi! PHP e C/C++)
    Per piacere lo supporti!

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,802
    ciao grazie infinite per avermi risposto , ti voglio fare vedere le due classi magari riusciamo a modificare la classe ... posto la mia ::::
    Codice PHP:
    class DB{
    var 
    $dbcore;
    var 
    $host ='localhost';
    var 
    $user ='root';
    var 
    $pass;
    var 
    $name;
        
    //PHP5 Constructor
        
    function __construct() {
            global 
    $db_host,$db_user,$db_pass,$db_name;
            
    $this->host $db_host;
            
    $this->user $db_user;
            
    $this->pass $db_pass;
            
    $this->name $db_name;
        }
        
    //PHP4 Constructor
        
    function database() {
            global 
    $db_host,$db_user,$db_pass,$db_name;
            
    $this->host $db_host;
            
    $this->user $db_user;
            
    $this->pass $db_pass;
            
    $this->name $db_name;
        }
     function 
    connect()
     {
      
    $this->dbcore = @mysql_connect($this->host,$this->user,$this->pass)or die("non riesco a connettermi".mysql_error());
      @
    mysql_select_db($this->name,$this->dbcore)or die("non riesco selezionare il database");
     }

      function 
    disconnect()
     {
      @
    mysql_close($this->dbcore);
     }
        function 
    ping() {
            if (!
    mysql_ping($this->dbcore)) {
                
    $this->disconnect();
                
    $this->connect();
            }
        }
        function 
    query($sql) {
            
    $result mysql_query($sql,$this->dbcore);

           if( ! 
    $result )
           {
           return 
    false;
           
           }


            return 
    $result;
        }
        function 
    getrow($sql) {
            
    $result $this->query($sql);
            
    $returned mysql_fetch_assoc($result);
            @
    mysql_free_result($result);
            return 
    $returned;
        }
        function 
    getlist($sql) {
            
    $returned = array();
            
    $result $this->query($sql);
            while (
    $row mysql_fetch_assoc($result)) {
                
    $returned[] = $row;
            }
            @
    mysql_free_result($result);
            return 
    $returned;
        }
        function 
    getnumrows($sql) {
            
    $result $this->query($sql);
            
    $num mysql_num_rows($result);
            @
    mysql_free_result($result);
            return 
    $num;
        }

    questa e la classe originale :
    Codice PHP:
    class flor_db_process{
      
      var 
    $query "";
      
      var 
    $isFetchMode false;
      var 
    $isUpdateMode false;
      var 
    $isInsertMode false;

      var 
    $resultSet null;
      var 
    $affRows=0;
      var 
    $numRows=0;
      var 
    $fieldCount 0;
      
      var 
    $errStr "";
      var 
    $hasErr false;
      
      var 
    $con null;
      var 
    $isDBConnected false;
      
      function 
    DBprocess2()
      {
          
    $this->openCon();
      }
      
      function 
    openCon()
      {
        
    $this->closeCon();
      
        global 
    $db;
        
          
    $dbname ="";
        
          
    $db_Domain;
          
    $dbname $cmtDB;


        
    //connecting with mysqli
        //
        
    $this->con mysqli_init();
        
    /* set connection options */
        
    $this->con->options(MYSQLI_INIT_COMMAND"SET AUTOCOMMIT=0");
        
    $this->con->options(MYSQLI_OPT_CONNECT_TIMEOUT5);
        
    /* connect to server */
        
    error_reporting(0);

        if (!
    defined("DB_DOMAIN") || !defined("DB_USER") || !defined("DB_PASS") || !defined("DB_NAME"))
            exit(
    "include common.php?.. db connect info missing for DBProcess2");

        
    $this->con->real_connect(DB_DOMAIN,DB_USER,DB_PASS,DB_NAME,DB_PORT);
        
        
    error_reporting(E_ALL E_NOTICE);
        if (
    mysqli_connect_errno()) 
        {
            
    $this->hasErr    =    true;
            
    $this->errStr "Connect failed: \n" mysqli_connect_error();
            exit(
    $this->errStr);    
        }
        else
        {
            
    $this->hasErr=false;
            
    $this->isDBConnected=true;
        }

      }

      
    //function to close db connection     
      
    function closeCon()
      {     
        
    //disconnecting with mysqli
        //
        
    if ($this->isDBConnected)
            
    $this->con->close();
                
        
    $this->con=null;
      }
      
      function 
    processQuery()
      {
          global 
    $errReportingType;
      
          if (!
    $this->query)
            return 
    null;
            
        if (!
    $this->con)
            
    $this->openCon();
        
        
    error_reporting(0);    
        
    $tmpResult $this->con->query($this->query);

        
    error_reporting($errReportingType);
        
        if (
    $this->con->error=="")
        {
            
    $this->hasErr false;
              if (
    $this->isFetchMode)
              {
                  
    $this->resultSet $tmpResult;
                if (
    $tmpResult)
                {
                      
    $this->numRows $tmpResult->num_rows;
                    
    $this->fieldCount $this->field_count;    
                }
                  else
                    
    $this->numRows 0;                
              }
            elseif(
    $this->isUpdateMode)    
            {
                  
    $this->affRows $this->con->affected_rows;
            }
            elseif(
    $this->isInsertMode)
            {
                  
    $this->affRows $this->con->affected_rows;
                  return 
    $this->con->insert_id;        
            }
        }
        else
        {
              
    $this->hasErr true;
            
            
    $this->errStr $this->con->error;
            
            if (
    APPMODE!="live")
                
    $this->errStr $this->query."___".$this->errStr;
            
            if (
    $this->isInsertMode)
                return 
    null;
        }
      }
      
      function 
    fetchQuery($qry)
      {
          
    $this->query         $qry;
          
    $this->isFetchMode     true;
          
    $this->isUpdateMode    false;
          
    $this->isInsertMode    =false;
          
    $this->processQuery();
          
      }

      function 
    insertQuery($qry)
      {
          
    $this->query         $qry;
          
    $this->isFetchMode     false;
          
    $this->isUpdateMode    false;    
          
    $this->isInsertMode true;
          
    $insert_id $this->processQuery();
          
        return 
    $insert_id;
      }

      function 
    updateQuery($qry)
      {
          
    $this->query         $qry;
          
    $this->isFetchMode     false;
          
    $this->isUpdateMode    true;    
          
    $this->isInsertMode false;
          
    $this->processQuery();
        
      }
      
      function 
    getRow()
      {
        
    $row $this->resultSet->fetch_row();
            
          if (isset(
    $row))
              return 
    $row;
          else
              return 
    null;
      }
      
      function 
    getRow2()
      {
        
    $row $this->resultSet->fetch_assoc();
        
          if (isset(
    $row))
              return 
    $row;
          else
              return 
    null;
      }
      
      function 
    reset()
      {
          
    mysqli_data_seek($this->resultSet,0);
      }
        

    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    hmm. forse questo:

    Codice PHP:
    function connect($host=$this->host,$user=$this->user,$pass=$this->pass,$db=$this->name)
    {
      
    $this->dbcore = @mysql_connect($host,$user,$pass)or die("non riesco a connettermi".mysql_error());
      @
    mysql_select_db($db,$this->dbcore)or die("non riesco selezionare il database");

    non ho provato xche non ho il script. cmq penso il questo script si fà.

    Per usare:

    1.) principale database è usato se non si definire.
    ad esempio:
    Codice PHP:
    $db = new DB;
    $db->connect(); 
    2.) puoi si definire un altre database
    Codice PHP:
    $db2 = new DB;
    $db2->connect('HOST','USER','PASS','DB_NAME'); 
    quest'uno è buon o no?

    Ciao,
    Dennis
    Nuovo Blog di Programmazione! (Lo ha i tutti tipi! PHP e C/C++)
    Per piacere lo supporti!

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 © 2025 vBulletin Solutions, Inc. All rights reserved.