PHP Script to create tables in Database

<?php

# Datbase Script of a DomianInfoTool
require("config.php");
define('TBL_DOMAIN','tbl_domain');
define('TBL_CATEGORY','tbl_category');

 # Drop Table From Database If With Any Of These Name Exist..

   mysql_query('drop table if exists '.TBL_DOMAIN);
   mysql_query('drop table if exists '.TBL_CATEGORY);
 
 
 #***************************************************************************************************************************************
 
 # Create Table TBL_Domains.It include Information about Domains....

 mysql_query("create table ".TBL_DOMAIN."
              (   
                `id_domain`                      MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
                `domain_name`                    varchar(200) NOT NULL,
                `domain_email`                  varchar(60),
                `domain_contact_url`            varchar(60),
                `_date_create`                   DATE NOT NULL,
                `_date_modify`                  DATE NOT NULL,
                PRIMARY KEY(`id_domain`)                     
              ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
             
#***************************************************************************************************************************************
#Create Table TBL_CATEGORY.It include Information about Categories.
 
  mysql_query("create table ".TBL_CATEGORY."
              (   
                `id_category`                      smallint unsigned NOT NULL AUTO_INCREMENT,
                `category_name`                    varchar(50) NOT NULL,
                `category_description`          varchar(255),
                `_date_create`                     DATE NOT NULL,
                `_date_modify`                     DATE NOT NULL,
                PRIMARY KEY(`id_category`)                     
              ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
             
              mysql_query("insert into tbl_category (category_name,category_description,_date_create,_date_modify) values('Uncatorized','Uncatorized sites','2009-10-24','2009-10-24')");
              mysql_query("insert into tbl_category (category_name,category_description,_date_create,_date_modify) values('Education','Educational sites','2009-10-24','2009-10-24')");
              mysql_query("insert into tbl_category (category_name,category_description,_date_create,_date_modify) values('Social','Social sites','2009-10-24','2009-10-24')");
              mysql_query("insert into tbl_category (category_name,category_description,_date_create,_date_modify) values('E-Commerce','E-Commerce','2009-10-24','2009-10-24')");
             
#***************************************************************************************************************************************   
Execution:

1. Create a config.php file at same location which include the required information to connect to phpMyadmin and select database
2.Run the script on locanhost.

#***************************      
?>         

No comments:

Post a Comment