Okay, on errors.php, I have the following class:
//Errors Class
class Errors
{
//For database errors
function db_error($code)
{
switch($code)
{
//If a connection to host could not be made
case 1: $message = 'A connection to the host could not be made!'; break;
//If the database couldn't be selected
case 2: $message = 'The database could not be selected!'; break;
}
//Display message
echo '<b>' . $message . '</b>';
}
}
//Initialize errors class object
$ERROR = new Errors;
In mysql.php, I have the following:
//MySQL Connection Function
function connect()
{
global $ERROR;
// Switch database connection types (between persistent and non persistent)
switch($type)
{
case 1: $connection = mysql_connect($host, $user, $pass); break;
case 2: $connection = mysql_pconnect($host, $user, $pass); break;
}
if(!$connection) // If a connection couldn't be made...
{
$ERROR->db_error(1);
error_mail();
exit();
}
else
{
//Select database
$select = mysql_select_db($db, $connection);
// If database couldn't be sellected...
if(!$select)
{
$ERROR->db_error(2);
error_mail();
exit();
}
}
}
Then in index.php. I do the following:
include('errors.php');
include('mysql.php');
connect(1, 'localhost', '123', 'pwd', 'my_db');
This is the error I get:
Fatal error:Call to a member function on a non-object in /home/oox/public_html/beta/sources/mysql.php on line 16
My question is, why am I getting this error? I mean I set $ERROR to use the Errors class.