So guys
I have program written in php and requires a database with two tables.I want the programe to check that a database exists and if not automatically create database and it's tables. can anyone suggest me a suitable way.

<?php
mysql_connect('localhost','root');
mysql_query("CREATE DATABASE IF NOT EXISTS employees");
mysql_query("USE employees");
mysql_query("DROP TABLE IF EXISTS employees");
mysql_query("CREATE TABLE employees (
SSN varchar (30) NOT NULL,
firstName varchar (30) NOT NULL,
lastName varchar (30) NOT NULL,
birthday date NOT NULL,
employeeType varchar (30) NOT NULL,
departmentName varchar (30) NOT NULL,
PRIMARY KEY (SSN)
) TYPE=INNODB");
echo "Database and table created successfully...";
?>

You can do it this way..

Cheers,
Naveen

commented: Very nice example +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.