There is an error in function lock_may_be_available() on my website.
Base table or view not found: 1146 Table 'external_database.semaphore'

Detailed error:

2017/11/08 01:27:29 [error] 15351#15351: *1900214 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'PDOException'
with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'external_DB.semaphore' doesn't exist'
in /var/www/htdocs/includes/database/database.inc:2171
Stack trace:
#0 /var/www/oarlive.rschooltoday.com/htdocs/includes/database/database.inc(2171): PDOStatement->execute(Array)
#1 /var/www/oarlive.rschooltoday.com/htdocs/includes/database/database.inc(683): DatabaseStatementBase->execute(Array, Array)
#2 /var/www/oarlive.rschooltoday.com/htdocs/includes/database/database.inc(2350): DatabaseConnection->query('SELECT expire, ...', Array, Array)
#3 /var/www/oarlive.rschooltoday.com/htdocs/includes/lock.inc(167): db_query('SELECT expire, ...', Array)
#4 /var/www/oarlive.rschooltoday.com/htdocs/includes/lock.inc(146): lock_may_be_available('schema:runtime:...')
#5 /var/www/oarlive.rschooltoday.com/htdocs/includes/bootstrap.inc(433): lock_acquire('schema:runtime:...')

Example of database connection in settings.php file:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'drupal_DB',
      'username' => 'user',
      'password' => 'pswd',
      'host' => '10.128.150.200',
      'port' => '3306',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
  'my_external_DB' => 
  array (
    'default' => 
    array (
      'database' => 'external_DB',
      'username' => 'other_user',
      'password' => 'other_pswd',
      'host' => '10.128.80.230',
      'port' => '3306',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

Example of menu item

$items['mymodule/%'] = array(
  'page callback' => 'drupal_get_form',
  'page arguments' => array('my_module_function_form',1),
  'access arguments' => array('access content'),
  'file' => 'my_module.file.inc',
  'type' => MENU_CALLBACK,
);

Example function:

function my_module_function_form($form, &$form_state){
  db_set_active('external_DB');

    $result = db_select([query to external_DB])->fields([some fields])->condition([some conditions])->execute()->fetchAll();;

  db_set_active();

  [other codes]
  ...
  ...

  return $form;
}

Sometime this function is called when the current database connection is still 'external_DB'.
It causes an error: Table 'external_DB.semaphore' doesn't exist'

'external_DB' is not drupal core/module database. I use it to store my data.

if I remove the 'db_select', the error does not occur. When I add 'db_select' back, the error occurs again.

Comments

fsakinata created an issue. See original summary.

arruk’s picture

I'm having the same issue and it's relatively new. I first saw it a month or so ago on some code that had been working for well over a year started reporting the same errors reported above. Today I am seeing it on code that worked on Tuesday. Is there a chance this is related to an update?

Version: 7.44 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.

quietone’s picture

Issue tags: -database, -lock, -lock.inc, -semaphore