MyBB Community Forums

Full Version: Make DB drivers more dinamic!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
require_once MYBB_ROOT."inc/db_".$config['database']['type'].".php";

switch($config['database']['type'])
{
	case "sqlite3":
		$db = new DB_SQLite3;
		break;
	case "sqlite2":
		$db = new DB_SQLite2;
		break;
	case "pgsql":
		$db = new DB_PgSQL;
		break;
	case "mysqli":
		$db = new DB_MySQLi;
		break;
	default:
		$db = new DB_MySQL;
}

// Check if our DB engine is loaded
if(!extension_loaded($db->engine))
{
	// Try and manually load it - DIRECTORY_SEPARATOR checks if running windows
	if(DIRECTORY_SEPARATOR == '\\')
	{
		@dl('php_'.$db->engine.'.dll');
	} 
	else 
	{
		@dl($db->engine.'.so');
	}
	
	// Check again to see if we've been able to load it
	if(!extension_loaded($db->engine))
	{
		// Throw our super awesome db loading error
		$mybb->trigger_generic_error("sql_load_error");
	}
}

I think that each database implementation should have a is_installed method which looks if the engine is installed, what if it isn't implemented as extension?

And also i would stick a class naming convention for that, so we can write a custom database engine without having to edit the init.php file.
You can only have a DB engine installed as an extension to PHP.
Shouldn't we be using the PHP_OS constant to determine the OS instead of the DIRECTORY_SEPARATOR?
(2008-10-13, 10:34 PM)laie_techie Wrote: [ -> ]Shouldn't we be using the PHP_OS constant to determine the OS instead of the DIRECTORY_SEPARATOR?

The if's pretty much check either Windows or Not Windows. If it's a forward slash that's windows, if it's a backwards slash then it's not windows.
(2008-10-13, 02:54 PM)flash.tato Wrote: [ -> ]And also i would stick a class naming convention for that, so we can write a custom database engine without having to edit the init.php file.
How would you do that? (without using eval())
A crude example.
class DB_mysql
{
function __construct()
{
   echo "PHP is good";
}
}
$class = "DB_" . "mysql";
$db = new $class();

The goodies of PHP Toungue

Don't think of eval as the solution for every problems Wink, if there are other solutions that don't need eval'ing other PHP code then stick with them. Wink
Okay, I could've sworn last time I tried doing a "new $class", PHP spat an error at me...

Forget what I said then.
So what do you think about this idea? Smile

And TikiTiki what about if there is an engine which doesn't need extension?
(2008-10-14, 12:00 PM)flash.tato Wrote: [ -> ]And TikiTiki what about if there is an engine which doesn't need extension?

There won't be. You need an extension through PHP in order to be able to use the functions provided.
That isn't true.

Theoretically i can write a my Database Engine into file and making pure PHP classes instead of writing an extension. Smile

The best is a
static function is_installed()
into classes
Pages: 1 2