First off, there's an error there. It's supposed to be mysql_errno() since it's a function call. Both functions uses the latest created db link unless a link is explicitly specified like this
$link = mysql_connect( /* ... */);
$result = mysql_query("Will not work");
echo mysql_errno($link);
mysql_errno() shows an error number and mysql_error() shows an error message.
$result = mysql_query("Something that goes wrong");
/* $result is now false, so it can't be used with functions that take a result set resource, such as
mysql_num_rows or mysql_fetch_assoc
If it is indeed a result set resource, then the if check below evaluates to false and is bypassed
*/
if (!$result) {
// my suggestion, which invokes the current error_handler (may display, mail, write to file)
error_log(mysql_errno() . ': ' . mysql_error());
// or NogDog's suggestion, which write to standard output and terminates the script
die(mysql_errno() . ': ' . mysql_error());
}
/* With my approach, you'd somehow need to deal with not proceeding to use $result with
mysql functions, since they will fail. e.g */
else {
// mysql_functions here
}
You should follow a similar approach when conneting to the db as well
$link = mysql_connect( /* ... */);
if (!$link) {
// decide what to do...
}