Disable lock_release_all I am testing my module, using a custom SQLite database. It has minimal amount of tables, necessary for the module. I run this function.

function test_header(&amp;$modules, &amp;$path_var = null) {
  $file_path = dirname(__FILE__);
  $path = preg_replace('/sites.*/', "", $file_path);
  $path = substr_replace($path ,"",-1);
  $_SERVER['DOCUMENT_ROOT'] = $path;

  define('DRUPAL_ROOT', $path);

  if (!is_null($path_var)) {
    $path_var = $path;
  }

  error_reporting(E_ALL ^ E_NOTICE);
  $path .= DIRECTORY_SEPARATOR . 'includes'.  DIRECTORY_SEPARATOR . 'bootstrap.inc';
  require_once($path);
  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);

  foreach($modules as $value) {
    drupal_load('module', $value);
  }

  return $file_path;
}


I run it with modules that need to be loaded.

$modules = array("members");
$file_path = test_header($modules);


Then I load the SQLite database, using this function.

function set_db($db_name, $db_alias, $driver = 'sqlite') {
  $test_database = array(
    'database' =&gt; $db_name,
    'username' =&gt; 'user',
    'password' =&gt; '',
    'host' =&gt; 'localhost',
    'driver' =&gt; $driver,
  );

  Database::addConnectionInfo($db_alias, 'default', $test_database);
  db_set_active($db_alias);
}


For one of the modules it works correctly. But for another one it gives an error, when I change DRUPAL_BOOTSTRAP_DATABASE to DRUPAL_BOOTSTRAP_FULL.


  General error: 1 no such table: semaphore: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) ; Array([:db_condition_placeholder_0] => 8994220325229a65a473108.08075181)
  in lock_release_all()


Without DRUPAL_BOOTSTRAP_FULL it gives some cryptic error.

It seems that it runs this function in the end, and it doesn't find the semaphore table in the SQLite database.

How can I turn off this function and everything else unnecessary?
The lock system is initialized during bootstrap (during the DRUPAL_BOOTSTRAP_VARIABLES phase, which follows the DRUPAL_BOOTSTRAP_DATABASE one) using the following code.

// Initialize the lock system.
require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc');
lock_initialize();


You could:


Bootstrap Drupal to the DRUPAL_BOOTSTRAP_DATABASE phase
Change the value of the lock_inc Drupal variable to make it point to an include file containing your implementation of the lock system, with functions that don't do anything
Execute the rest of the code, including the one to raise the bootstrap level to the desired one


Since you are loading other modules, this resolves the problem with the lock database table, but it doesn't avoid that modules try to access a database table that normally exists on a Drupal installation, including the ones they install. If you need to execute a query (for example, a SELECT) on a database that is different from the default one you could use the following code.

Database::addConnectionInfo($db_alias, 'default', $test_database);
query = Database::getConnection('default', $db_alias)-&gt;select('table name', 'table alias');
// The rest of the code goes here.


The first two arguments for Database::addConnectionInfo() and Database::getConnection() are flipped: The first argument of Database::addConnectionInfo() becomes the second argument of Database::getConnection(), and the second argument of Database::addConnectionInfo() becomes the first argument of Database::getConnection().