create-mysql-database-with-php

create-mysql-database-with-php
To create a database use the mysql_query() function to execute an SQL query like this

Please note that the query should not end with a semicolon.
PHP also provide a function to create MySQL database, mysql_create_db(). This function is deprecated though. It is better to use mysql_query() to execute an SQL CREATE DATABASE statement instead like the above example.

If you want to create MySQL database using PHP mysql_create_db() function you can do it like this :

If you want to create tables in the database you just created don’t forget to call mysql_select_db() to access the new database.
Note: some webhosts require you to create a MySQL database and user through your website control panel (such as CPanel). If you get an error when trying to create database this might be the case.
Creating the Tables
To create tables in the new database you need to do the same thing as creating the database. First create the SQL query to create the tables then execute the query using mysql_query() function.

Example : contact.php
Source code : contact.phps

Of course when you need to create lots of tables it’s a good idea to read the query from a file then save in $query variable instead of writing the query in your script.

Deleting a Database
As with creating a database, it is also preferable to use mysql_query() and to execute the SQL DROP DATABASE statement instead of using mysql_drop_db()