first you need to create connection to the database
mysql_connect(servername,username,password);
below is an example we store the connection in a variable ($con) for later use in the script. The "die" part will be executed if the connection fails:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
mysql_close above will close the connection automatically when the script ends.
|