Connecting to a MySQL Database
resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )
<?php
try {
$mysqlhost = "localhost";
$mysqluser = "root";
$mysqlpass = "";
if ($db = mysql_connect ($mysqlhost,$mysqluser,$mysqlpass)){
echo "Successfully connected to the database.";
mysql_close ($db);
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
?>
Related examples in the same category