Changeset 655

Show
Ignore:
Timestamp:
10/04/2007 10:54:25 PM (14 months ago)
Author:
zombor
Message:

Add list_tables() and table_exists()

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/controllers/welcome.php

    r650 r655  
    8181                foreach($query as $item) 
    8282                { 
    83                         print_r($item); 
     83                        //echo '<pre>'.print_r($item, true).'</pre>'; 
    8484                } 
    8585 
    86                 die; 
    87  
     86                echo '<pre>'.print_r($this->db->list_tables(), true).'</pre>'; 
     87                echo $this->db->table_exists('pages'); 
    8888                print "Numrows: ".$query->num_rows()."<br/>"; 
    8989                print "<pre>".print_r($this->database, TRUE)."</pre><br/>"; 
  • trunk/system/libraries/Database.php

    r654 r655  
    693693                $this->where = array(); 
    694694        } 
     695         
     696        /** 
     697        * Returns an array of table names 
     698        * 
     699        * @access      public 
     700        * @return      array 
     701        */ 
     702        public function list_tables() 
     703        { 
     704                if (!$this->connected) $this->driver->connect($this->config); 
     705                 
     706                return $this->driver->list_tables(); 
     707        } 
     708         
     709        /** 
     710        * Determine if a particular table exists 
     711        * @access      public 
     712        * @return      boolean 
     713        */ 
     714        public function table_exists($table_name) 
     715        { 
     716                return ( ! in_array($table_name, $this->list_tables())) ? FALSE : TRUE; 
     717        } 
     718         
    695719 
    696720} // End Database Class 
  • trunk/system/libraries/drivers/Database_Mysql.php

    r644 r655  
    300300                return mysql_real_escape_string($str, $this->link); 
    301301        } 
     302         
     303        /** 
     304        * List table query 
     305        * 
     306        * Generates a platform-specific query string so that the table names can be fetched 
     307        * 
     308        * @access      private 
     309        * @return      string 
     310        */    
     311        public function list_tables() 
     312        { 
     313                $sql = "SHOW TABLES FROM `".$this->db_config['connection']['database']."`"; 
     314                $query = $this->query($sql); 
     315                $query = $query->result(); 
     316                 
     317                $retval = array(); 
     318                foreach($query as $row) 
     319                { 
     320                        $column = 'Tables_in_'.$this->db_config['connection']['database']; 
     321                        $retval[] = $row->$column; 
     322                } 
     323                 
     324                return $retval; 
     325        } 
    302326 
    303327} // End Database_Mysql Class