PHP MySql Create database and tables

PHP MySql Create database and tables tutorial will explain you how to Create database in php? with Examples. Every database consists of one or more tables, which store the data/information of database. Each table has its own unique name and consists of columns and rows.

Syntax for Create database in Mysql:

CREATE DATABASE [IF NOT EXISTS] database_name;

mysql_create_db() is not supported by PHP 5. mysql_create_db() is deprecated.

It is preferable to use mysql_query() to execute the statement above in PHP.
So, we’re going to use sql command, mysql_query() to create a database .

Create a table in MySql database

We have our database area created, but that is just giving a name to the area. It is a big blank space. The next step is to put at least one table in it.

Here is the MySql syntax for creating table:

CREATE TABLE table_name (field1_name TYPE(SIZE), field2_name TYPE(SIZE));

For creating table using PHP, we have to use CREATE TABLE in mysql_query() function.

Example on Create a table in MySql database:

Above example will create the TABLE with name address_book, columns with name first_name, last_name and phone_number and will assign them a appropriate data type.

Primary keys and auto increment fields

MySQL Auto increment Primary Key is used to allow a unique number to be generated when a new record is inserted into a table.

Primary key and auto increment field:

Example on PHP MySql Create database and tables:

SHARE
Previous articlePHP MySql Connect to a database
Next articlePHP MySql insert into
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!