Inside a function you use the global keyword like in this example
<?php
//common_db.inc
$dbhost = 'can't show';
$dbusername = 'can't show';
$dbuserpassword = 'can't show';
$default_dbname = 'can't show';
$MYSQL_ERRNO = ' ';
$MYSQL_ERROR = ' ';
function db_connect()
{
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!link_id)
{
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
}
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()
{
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR))
{
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
?>
For security reasons I had to replace some stuff with can't show at the top 😉 Also sry about the formatting