Table Creation
To create Database in MySQL:
Using MySQL console:
i) Open MySQL console from WAMP server icon
ii) Enter the password (generally it is blank, unless you have set any)
ii) Type create database database_name. Enter your desired database name in place of database_name e.g. create database student or create database Employee etc. SQL is not a case sensitive language, but database name or table name is case sensitive. After that to open the database type use database_name
OR
Using phpMyAdmin:
i) Start WAMP server
ii) Click on the icon you will get a menu
iii) After clicking phpMyAdmin option, https://localhost/phpadmin/ page will be open.
iv) Select any appropriate name for your new database in the create new database textbox and click create button.
Creating A database With PHP
To create a table in PHP is slightly more difficult than with MySQL. It takes the following format:
$con = mysql_connect("localhost","user1","password1");
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);
?>
Table creation -
$con = mysql_connect("localhost","user1","password1");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
?>