// function to report a viewer-friendly error message
function sql_error($M_ERROR='') {
$M_ERRNO = (mysql_errno()) ? mysql_errno() : 0;
$M_ERROR = ($M_ERROR != '') ? $M_ERROR : mysql_error();
echo "<div style='color:orangered; margin-left:4em'>error number " .$M_ERRNO. ": " .$M_ERROR. "</div>";
return true;
}
then you can use the function thus:
// function to connect to MySQL
function mysqlConnect() {
global $host, $user, $password;
$link = @mysql_connect($host,$user,$password);
if (!$link) {
$M_ERROR = mysql_error()."<br /><br />Could not connect to $host";
sql_error($M_ERROR);
return 0;
} else {
return $link;
}
}