View Single Post
Old 09-19-2007, 08:11 PM   #1 (permalink)
Haris
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default How to check if a table exists?

How to check if a table exists in the database? I want to execute the function in my class which will create the table if only the table doesn't exists already.

EDIT:

As far as I know, I can accomplish it in this way:

PHP Code:
        /*
         * Summary:     Creats default database table for administration panel
         */
        
        
class Admins extends Database{
        
        public function 
__construct(){
            
$szSQL "SELECT * FROM admins";
            
$szResult $this->execute($szSQL);
            
$iNumRows mysql_num_rows($szResult);
            if(
$iNumRows == 0){
            
$szSQL 'CREATE TABLE `classes`.`admins` (
                        `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
                        `user` VARCHAR( 225 ) NOT NULL ,
                        `pass` VARCHAR( 225 ) NOT NULL ,
                        `rank` INT( 1 ) NOT NULL ,
                        UNIQUE (`id`)
                        ) ENGINE = InnoDB '
;
            @
$this->execute($szSQL);
            }
        } 
Mission failed or accomplished?
Haris is offline  
Reply With Quote