I'm attempting to write my first function. Basically, I have 3 databases on my server: sohh, ohha2001 and vb114.

For the past 4 days, I've only been connecting to one database, sohh, but now I want to connect to vb114.

In a common.php file I had the following:

$hostname = "hostname";
$username = "username";
$password = "password";

$dbcnx = @mysql_connect($hostname, $username, $password);

if (!$dbcnx) {
echo("<P>Unable to connect to the database server at this time.</P>");
exit();
}

// function to connect the database
mysql_select_db(sohh, $dbcnx);

// ensure the database is available
if (! @mysql_select_db(sohh)) {
echo("Unable to locate the <b>$dbase</b> database at this time.");
exit();
}

Then in the top of cage_list.php I have:

require("common.php");

Then later on in in cage_list.php page I have:

$result = mysql_query($query);

if (!$result) {
echo "<B>Error performing query/B> " . mysql_error();
exit();
}

...yadda-yadda-yadda...

See http://www.sohh.com/pub2000/cage_list.php for the outcome.

So I tried to make the way I connect to my database a function. So, in common.php I put:

$hostname = "hostname";
$username = "username";
$password = "password";

function connect_database($dbase) {

$dbcnx = @mysql_connect($hostname, $username, $password);

if (!$dbcnx) {
echo("<P>Unable to connect to the database server at this time.</P>");
exit();
}

// function to connect the database
mysql_select_db($dbase, $dbcnx);

// ensure the database is available
if (! @mysql_select_db($dbase)) {
echo("Unable to locate the <b>$dbase</b> database at this time.");
exit();
}
return;
}

Then in my cage_list.php, I put:

connect_database(sohh);

I get the message "Can not connect to the databsae" or something like that.

But no go...Any thoughts, comments or suggestions?
<Edited by ibeblunt on 01-09-2001 at 03:57 PM>