Here's how I do it... (the following is included in my "functions" file)
// Connection info
<?php
$db_host = "********";
$db_login = "********";
$db_password = "********";
$db_name = "********";
// Nifty error function
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
?>
Typical usage...
<?php
// Open db connection
if (!($conn = mysql_connect($db_host, $db_login, $db_password)))
die("***Cannot connect to database:" . mysql_error());
// Selecting my database
if (!(mysql_select_db($db_name, $conn)))
die("***Cannot select database:" . mysql_error());
$query = "SELECT blah blah FROM blah ORDER BY blah LIMIT blah";
// Run the query
if (!($result = @ mysql_query($query, $conn)))
die("***Error running query:" . mysql_error());
// Closing db connection
if (!(mysql_close($conn)))
die("***Error closing database:" . mysql_error());
?>
Something along those lines...