How to create a database?
Creating database is easy to do.

I am beginner to MySQL so I always have my self-study for this. I have a pdf file for this.
In creating database I use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

This is my first time to make program code through mysql create database. My database name is ENGR_DEPARTMENT. Take a look for the code.

<?php
$con=mysql_connect(“localhost”,”root”,””);
if(!con)
{
die(‘could not connect:’.mysql_error());
}

//create database
if(mysql_query(“CREATE DATABASE engr_department”,$con))
{
echo “database created”
}
else
{
echo “error creating database:”.mysql_error();
}
mysql_close($con);

?>

When I run the program, I got a error message like this Parse error: parse error, expecting `’,” or `’;” in C:\xampp\htdocs\sample\egr-create.php on line 12. When I go back to my code, there I saw that ; is missing in this phrase echo “database created” . So, to avoid some unnecessary code like what I have. Be careful in writing your codes even a single semi-colon is missing. Before you run your program make sure you have double check the codes to avoid some errors.
This is now my new code for creating database of ENGR_DEPARTMENT.


<?php
$con=mysql_connect(“localhost”,”root”,””);
if(!con)
{
die(‘could not connect:’.mysql_error());
}

//create database
if(mysql_query(“CREATE DATABASE engr_department”,$con))
{
echo “database created”;
}
else
{
echo “error creating database:”.mysql_error();
}
mysql_close($con);

?>

Awesome! No more errors.