Creating Database in PHP – With Coding

This blog explains about Creating Database in PHP – With Coding . It is illustrated very well below :


In last program we learned how to connect given database with PHP page. In this program, you can get an idea with how to create new database. If you have a basic knowledge in MySQL query, it will very helpful to understand to learn this PHP program.

Ok, Lets see the program

A database consists of one or more tables.

You will need special CREATE privileges to create or to delete a MySQL database.

Create a MySQL Database Using MySQLi and PDO

The CREATE DATABASE statement is used to create a database in MySQL.

Inserting Multiple Rows into a Table

You can also insert multiple rows into a table with a single insert query at once. To do this, include multiple lists of column values within the INSERT INTO statement, where column values for each row must be enclosed within parentheses and separated by a comma.

The following examples create a database named “myDB”:

/* Create new  database */
$host = “localhost”;
$user = “root”;
$pass = “”;
$connect=mysql_connect($host, $user, $pass);
$query=”create database Trainee”; // This is your MySQL query(Database name is: Trainee)
$mysql=mysql_query($query); // executes a query on a MySQL database.
echo “New Database is created successfully”;



New Database is created successfully


For the purpose of this tutorial on creating PHP contact form with MySQL, I assume that you have a PHP application installed on a web server. My setup is:

  • PHP 7.1
  • MySQL
  • Jquery/Ajax

To make sure that that I don’t get side-tracked by server level issues, I decided to host PHP application on Cloudways managed servers because the Platform offers a powerful PHP optimized environment.