You need to connect MySQL database before assessing it. This is done by mysql_connect function.
You should know the following terms before getting connected to MySQL server:
Name of the server. The default server name is localhost. Username and Password.
<?php
$con = mysql_connect(“localhost”,”Admin”,”1234″);
*above given server name, username and password are just examples. Practically you have to give your own server name, user name and password
$con = mysql_connect(“server name”, “username”, “password”);*
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
?>
After the script ends, the connection will get closed automatically. In case if you want to close MySQL database connection before the script ends, then follow the following code:
<?php
$con = mysql_connect(“localhost”,”Admin”,”1234″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_close($con);
?>
You may not need to create a database or user account if you are using MySQL server in a hosted environment, and if they supplied you with a username and database name.



