Go Back   Wiki NewForum > Career Forum (Documents/Tutorials/Advice) > Tech Forum & Tutorial > PHP Forum & Tutorial

Sponsored Links

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

Reply
Views: 1148 Source: CNN18.com, India-Forums, TellyChakkar, India, Times of India, Youtube, BollywoodLife, Rediff  
Thread Tools Rate Thread Display Modes
  #1  
Old 05-04-2009, 05:46 PM
welcomewiki welcomewiki is offline
Member
 
Join Date:
Dec 2008
Location:
India
Posts: 39,151
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.



Syntax

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.
Example

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";
}
else
{
echo "Error creating database: " . mysql_error();
} mysql_close($con);
?>
Create a Table

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

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
Reply

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 - 2018, vBulletin Solutions, Inc.