I use an access control script that I include on every page.
It includes my db connection script, verifies the user and leaves me with an established connection.
I never refer to it afterwards in any of my other scripts ie. I code $result = mysql_query($sql) and that is it. You only need to be specifying the connection if you have multiple database connections open, if you don't then why bother.
I have general purpose scripts that run my queries and then include different scripts according to the results, which in turn query the database for additional results. They also use mysql_real_escape_string which will definately fail if there is no db connection already in existance, and this use of mysql_real_escape_string is done by a function that resides in a common functions include file; which is itself included by my accesscontrol.
I just checked my access control script and the order in which I have things coded is as follows
<?php // stAccess.php
require_once 'stHeader.php';
require_once 'stCommon.php';
require_once 'stDb.php';
session_start();
dbConnect("mydb");
// etc
?>
<?php // page1.php
require_once 'stAccess.php';
// etc
?>
Never had a problem, even though the common functions file gets included before the db connection is established (had not thought about it before).
So what I'm getting at, at last :rolleyes: , is that you can 'pass' a connection down to included scripts.