Thread: Php
View Single Post
Old 10-30-2012, 07:31 PM   #9
henryc10
Registered User
 
Join Date: Oct 2012
Posts: 33
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.
henryc10 is offline   Reply With Quote