I’ve written some simple functions for database handling like this:
function dbOpen($db)
{
$username = "admin";
$password = "pass";
$hostname = "localhost";
$db = mysql_connect($hostname, $username, $password)
}
function dbClose($db)
{
mysql_close($db);
}
What I want to do is get access to the variable I passed to the dbOpen function like:
dbOpen($myDB);
$result = mysql_query('SELECT * FROM my_tbl',$myDB);
However, for some reason this function won’t initialize $myDB. Does anyone have any ideas what I’m doing wrong?
If you want to do that, you need to set up your database functions to take that variable passed as a reference. This here explains it.