You gotta dig into the manual on this one. It looks as though you haven't spent too much time in it.
The mysql_close( $link ); isn't needed either, as PHP will automatically close the connection when no other link is needed to be opened.
Also, you don't need to run this if statement:
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
Instead, you can just do this:
$link = mysql_connect("localhost", $user, $pass) OR die("Couldn't connect to MySQL: ".mysql_error());
Open the manual and learn, learn, learn...