Location: PHPKode > scripts > Tables Properties Progress ODBC > tables-properties-progress-odbc/tables.class.php
<?php
   /**
     * @todo Show tables Properties of Progress 10 Data Base
     * @author Gustavo Mena
     * @access public
     */
class tables{
    var $cn;
    /**
     * @todo Connect to DB
     * @author Gustavo Mena
     * @access private
     * @param string $strServer DSN
     * @param string $strUsername Username
     * @param string $strPassword Password
     */	
    function _connect($strServer, $strUsername, $strPassword){
     //Conexion a Progress 10
     putenv("LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/odbc/lib/");
     putenv("ODBCINI=/etc/odbc.ini");
     putenv("ODBCINSTINI=/etc/odbcinst.ini");
     $this->cn = odbc_connect($strServer, $strUsername, $strPassword);
    } 
	
	/**
     * @todo Constructor
     * @author Gustavo Mena
     * @access public
     */	
    function tables(){
     $this->_connect("Server", "user", "pass");
     // Register the destructor
     register_shutdown_function(array( &$this, "__destroy" ));
    }
    /**
     * @todo Destructor
     * @author Gustavo Mena
     * @access private
     */	
    function __destroy(){
    }
    
    /**
     * @todo Display the Data Source Name
     * @author Gustavo Mena
     * @access public
     */
    function getDSN(){
    	$result = odbc_data_source($this->cn, SQL_FETCH_FIRST);
        while($result)
        {
         if (strtolower("Progress101c_b01") == strtolower($result['server'])) {
          echo "<div >";
          echo '*** DSN: '.$result['server'].'<br>';   
          echo '*** Driver: '.$result['description'] . "<br>";
          echo "</div>";
          echo "<hr>";
          break;
         }
         else
         $result = @odbc_data_source($this->cn, SQL_FETCH_NEXT );
       }
    }
    
	/**
     * @todo Return  field name, field type, field len of $table in HTML Format
     * @author Gustavo Mena
     * @access public
     * @param string $table Table Name
	 * @return string $html
     */
    function getFieldName($table){
    	$sql = "SELECT * FROM $table WHERE 1=2";
    	$result = odbc_exec($this->cn,$sql);
    	for ($i=1; $i <= odbc_num_fields($result); $i++) $return_array[$i-1] = odbc_field_name($result, $i);
    	//return $return_array;
    	 $html="<table border=\"1\" bgcolor='#FFFFFF'  >";
         $html.="<tr style=\"font-weight:bold\"><td>FIELD_NAME</td><td>FIELD_TYPE</td><td>FIELD_LEN</td></tr>";
         $j=1;
         foreach($return_array as $nombre){
      	  $field_type = odbc_field_type($result, $j);
      	  $field_len = odbc_field_len($result,$j);
      	  $html.="<tr><td>$nombre</td><td>$field_type</td><td>$field_len</td></tr>";
      	  $j++;
         }
         $html.="</table>";
         return $html;
    }
    
	/**
     * @todo Return  Index of the table
     * @author Gustavo Mena
     * @access public
     * @param string $table Table Name
	 * @return result $result
     */
    function getIndex($table){
      $result = odbc_statistics($this->cn,"%" , "%"  , "$table"  , 1 , 1);
      return  $result;
    }
    
	/**
     * @todo Return  Procedures of DB
     * @author Gustavo Mena
     * @access public
     * @return result $result
     */
    function getProcedures(){
    	$result = odbc_procedures($this->cn,"%", "%", "%");
    	return $result;
    }
    
	/**
     * @todo Return  Pkey of Table
     * @author Gustavo Mena
     * @access public
     * @param string $table Table Name
     * @param string $db Data Base
	 * @return result $result
     */
    function getPrimaryKey($table,$db=NULL){
      //$result = odbc_primarykeys($this->cn, "$db", "PUB", "$table");
      $result = odbc_primarykeys($this->cn, "%", "PUB", "$table");
      return $result;
    }
    
   /**
     * @todo Display Colums of Table
     * @author Gustavo Mena
     * @access public
     * @param string $table Table Name
     * @param string $db Data Base
	 */
    function getColums($db,$table){
     $resu = odbc_columns($this->cn, "$db", "", "$table", "%");
     while (odbc_fetch_row($resu)) {
      echo odbc_result_all($resu,"border=1");
     }
    }
    
	/**
     * @todo Return  Tables in Array
     * @author Gustavo Mena
     * @access public
     * @param string $table Table Name
     * @return array $tables_output
     */
	function getTables($table=NULL){
      if($table!=NULL){
       //table name
       $table = odbc_tables($this->cn,"%","%","$table");
	   $tables_output=array();   
	   $tables_output = $this->getArrayTables($table);  
	   return $tables_output;     
      }else{
       //All
       $tables = odbc_tables($this->cn);
       $tables_output=array();   
	   $tables_output = $this->getArrayTables($tables);  
	   return $tables_output;     
     }
    }
    
	
	/**
     * @todo Return  Tables into 
     * @author Gustavo Mena
     * @access public
     * @param string $table Table Name
     * @return array $tables_output
     */
    function getArrayTables($result){
      $tables = array();
      
      while (odbc_fetch_row($result)){
       if (odbc_result($result,"TABLE_TYPE")=="TABLE"){
        $table_name = odbc_result($result,"TABLE_NAME");
        $tables[] = strtolower($table_name); 
       }
      } 
	  sort($tables);   
      return $tables;
    }
    
	
	/**
     * @todo Display Result inHTML
     * @author Gustavo Mena
     * @access public
     * @param string $result Resource
     */
    function displayRs($result){
    	odbc_result_all($result,"bgcolor='#FFFFFF' border='1'");
    }
	
     /*
     *Auxiliar Function for debug

    function dumpArray($array){
    	echo "<pre>";
    	print_r($array);
    	echo "</pre>";
    } 
   */
}

?>
Return current item: Tables Properties Progress ODBC