Keep in mind that I'm not a super-star PHP programmer.
That being said, I'd use a separate file for db connection and one for db configs (defining host, user, pass etc.):
// ---------DBConnect.php ---------------
include ('config.php');
class DB {
function connect() {
mysql_connect('...') or die('...');
// some more db-connection wise commands
}
// you could make the connection at object instantiation:
function __constructor() {
mysql_connect('...') or die('...');
// some more db-connection wise commands
// if you know you'll work with the same database, select it in here
mysql_select_db('...');
}
function query($query) {
mysql_query($query);
}
}
$db = new DBConnect();
And use this file all around:
include DBConnect.php;
// from hereafter I'll use $db, or $db->connect and $db->query
You could use singletons also.