Put all your db connection stuff in one file and include it on the pages you want to have db copnnection on.
Example:
File named "db.php"
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "";
$db = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
On every page you want db access use
include("./db.php");
At the top of the page