Extract the database abstraction layer If it's possible, how can I go about extracting the database abstraction layer to use in a non-Drupal site?
If you want to use the Drupal database code in a website, without bootstrapping Drupal, you need the following files:


includes/database/database.inc
includes/database/sqlite/database.inc
includes/database/mysql/database.inc
includes/database/pgsql/database.inc


The code in those files needs to be changed, as:


The code uses the DRUPAL_ROOT constant. You could remove the code using that constant, and replace it with code that automatically loads the include file containing the class. For example, the following code uses DRUPAL_ROOT because Drupal cannot use its code registry until there isn't a database connection active, as its code registry uses a database table.

// We cannot rely on the registry yet, because the registry requires an
// open database connection.
$driver_class = 'DatabaseConnection_' . $driver;
require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/database.inc';
$new_connection = new $driver_class(self::$databaseInfo[$key][$target]);
$new_connection-&gt;setTarget($target);
$new_connection-&gt;setKey($key);


It could be rewritten as follows, if you register your own function with spl_autoload_register().

$driver_class = 'DatabaseConnection_' . $driver;
$new_connection = new $driver_class(self::$databaseInfo[$key][$target]);
$new_connection-&gt;setTarget($target);
$new_connection-&gt;setKey($key);

The functions use the global $databases, which is normally defined in the settings.php file. You could replace that variable with a static property of the Database class.