* Gets the database instance, initializing it if needed
*
* The correct database instance to initialize will be determined from the
* $Config['database']['engine'] preference.
*
* The database class to use will be Database + (preference engine, capitalized)
*
* This method will creates an instance of the specified object,
* calling the load static method from this object class.
*
* Example:
* <code>
* $Config['database']['engine'] = 'quux';
* $db = Database::load(); //Database:load() will call DatabaseQuux:load();
* </code>
*
* @return Database the database instance
*/
staticfunctionload(){
global$Config;
if(
!array_key_exists('database',$Config)||
!array_key_exists('engine',$Config['database'])
){
//database is not configured or engine is not specified
message_die(GENERAL_ERROR,'A database engine (a MySQL variant is recommended) should be configured. Please ensure you have a ["database"]["engine"] value in the configuration.',"Setup issue");
}else{
//engine is specified in the configuration
$engine=$Config['database']['engine'];
}
$engine_file='includes/db/'.$engine.'.php';
$engine_class='Database'.ucfirst($engine);
if(!file_exists($engine_file)){
message_die(GENERAL_ERROR,"Can't initialize $engine database engine.<br />$engine_file not found.",'Setup issue');
}
require_once($engine_file);
if(!class_exists($engine_class)){
message_die(GENERAL_ERROR,"Can't initialize $engine database engine.<br />$engine_class class not found.",'Setup issue');