Yes, I should have mentioned mysql_select_db and the use of variable to set parameters. Here is the include file that I use for my database access (as recommended by "Beginning PHP"
?php
//common_db.inc
//Mark Beal 21/10/02
//This script performs the connection to the database and passes back any errors
//Set here the database parameters
$dbhost = 'localhost';
$dbusername = 'root';
$dbuserpassword = 'monkey';
$default_dbname = 'resourceplanner';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
//test for invalid username or password
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
//test for invalid/empty $dbname
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
//if the global variable $MYSQL_ERROR is empty then output the error messages defined above
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
?>
the file is then used in a .php script thus:
global $default_dbname;//used in function db_connect - must be available to this script
include "common_db.inc";
error_reporting(0);
//connect to mysql database resourceplanner
$link_id = db_connect();
if(!$link_id) die(sql_error());
Hope this may be of help to people