Problem with accessing static variable
Posted: Mon Jun 07, 2010 8:53 am
Here's my code:
But if I make the following call:
I get the following fatal error:
What is causing this fatal error? Thanks for your help.
Code: Select all
<?
include_once "./Database.class.php";
include_once "./defined.php";
/*****************************************************************************************************************
* Name: DbConnection
*
* Purpose: Class that manages single instantiation of a Database object (see Database.class.php)
*
****************************************************************************************************************/
class DbConnection {
private static $connnection;
/***********************************************************************************************
*
* Name: init
*
* Purpose: Instatiates a connection to the database
*
* Parameters: none
*
* Returns: none
*
************************************************************************************************/
public static function init() {
self::$connection = new Database(SERVER, USERNAME, PASSWORD, DBNAME);
}
/***********************************************************************************************
*
* Name: query
*
* Purpose: Handles queries to the database. This function will connect to the database run the specified query
* disconnect from the database and return the results as an array or a null on an error.
*
* Parameters:
* sql - the sql string used to query the database
*
* Returns: the result set, as an array, that resulted from running the query.
*
************************************************************************************************/
public static function query($sql) {
return self::$connection->query($sql);
}
/***********************************************************************************************************
* Name: execute
*
* Purpose: Handles the execution of sql on the database. Types of sql that should be sent here include INSERT,
* UPDATE, or anything that shouldn't return a result set.
*
* Incoming Parameters:
* sql - the sql string to execute on the database
*
* Returns: nothing
*
*************************************************************************************************************/
public static function execute($sql) {
self::$connection->execute($sql);
}
}
?>Code: Select all
DbConnection::init();Code: Select all
Fatal error: Access to undeclared static property: DbConnection::$connection in /home/user/public_html/DbConnection.class.php on line 42