Changeset 2302

Show
Ignore:
Timestamp:
12/16/10 07:04:29 (17 months ago)
Author:
petsagouris
Message:

[Branch 1.5] Better Database::table_exists() and Database::column_exists()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.5/libs/Database.php

    r2295 r2302  
    349349        public function table_exists($table_name) 
    350350        { 
    351                 $tables = $this->get_col("SHOW TABLES", 0); 
    352                 return (bool) in_array(DB_PREFIX.$table_name, $tables); 
     351                return (bool) $this->query("SHOW TABLES LIKE '".DB_PREFIX.$table_name."'"); 
    353352        } 
    354353 
     
    364363        public function column_exists($table_name, $column) 
    365364        { 
    366                 $sql = "SHOW COLUMNS FROM ".DB_PREFIX.$table_name; 
    367                 foreach ($this->get_col($sql, 0) as $column_name) { 
    368                         if ($column_name == $column) { 
    369                                 return FALSE; 
    370                         } 
    371                 } 
    372  
    373                 return FALSE; 
     365                return (bool) $this->query("SHOW COLUMNS FROM `".DB_PREFIX.$table_name."` LIKE '".$column."'"); 
    374366        } 
    375367