Go Back   Wiki NewForum > Career Forum > Tech Forum & Tutorial > PHP Forum & Tutorial

Sponsored Links

PHP Forum & Tutorial PHP Tutorial, Codes, Examples & Full End-To-End Process

Views: 1399  
Thread Tools Rate Thread Display Modes
Old 05-04-2009, 05:46 PM
welcomewiki welcomewiki is offline
Join Date:
Dec 2008
Posts: 42,030
Default PHP MySQL Create Database and Tables

A database holds one or multiple tables.
Create a Database

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


CREATE DATABASE database_name

To learn more about SQL, please visit our SQL tutorial.

To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

The following example creates a database called "my_db":

$con = mysql_connect("localhost","peter","abc123");
if (!$con)
die('Could not connect: ' . mysql_error());
} if (mysql_query("CREATE DATABASE my_db",$con))
echo "Database created";
echo "Error creating database: " . mysql_error();
} mysql_close($con);
Create a Table

The CREATE TABLE statement is used to create a table in MySQL.

CREATE TABLE table_name(
column_name1 data_type,column_name2 data_type,column_name3 data_type,


To learn more about SQL, please visit our SQL tutorial.
We must add the CREATE TABLE statement to the mysql_query() function to execute the command.

Reply With Quote

New topics in PHP Forum & Tutorial

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2019, vBulletin Solutions, Inc.