This is very very novice kind of thing. Every web application requires script like this. Usually we write the following in a file named which would later be included in files as needed.

$host = "localhost";
$dbname = "database_name";
$username = "user";
$password = "pass";

function dbConnect()
    global $host, $username, $password, $dbname;
    mysql_pconnect($host, $username, $password) or die("Error connecting to database");
    mysql_select_db($dbname) or die("Cannot select the database");

mysql_pconnect() makes a persistent connection. When connection it listens for any open connections and uses it if available. Also once the script ends it won’t close the connection. It will remain open for any further connections. It cannot also not closed with mysql_close() function.