I am using Drupal 7 functions externally, and I followed this tutorial for using Drupal functions externally; it works perfectly.

In test.php file I have loaded/included Drupal bootstrap.

When I run the script from command line (php test.php), it gives me the following error:

PDOException: SQLSTATE[42000] [1049] Unknown database 'default_drupal' in lock_may_be_available() (line 167 of /data/var/www/html/mcsu_sites_test01/includes/lock.inc).

How can I fix this error?

  • 1
    Hello, and welcome on Drupal Answers. May you show the code you are using on test.php?
    – apaderno
    Commented Sep 10, 2012 at 23:09

3 Answers 3


You could also try Drush. Once you've installed it, you can cd into your drupal root then run drush scr test.php. In that file, all Drupal functions will be available.


You need this section from scripts/drupal.sh:

// define default settings
$cmd = 'index.php';
$_SERVER['HTTP_HOST']       = 'default';
$_SERVER['PHP_SELF']        = '/index.php';
$_SERVER['REMOTE_ADDR']     = '';
$_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';

According to PDOException error , probably your problem is in db conection . drupal can not connect database .
which version of drupal you are using ?

check $databases or $db_url variables(according your drupal version) and it's properties set correctly

if your are usning Drupal 7

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'yourdatabase',
      'username' => 'usernameofdb',
      'password' => 'passwordofdbuser',
      'host' => 'dbhost', //localhost if you are localy worked
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',

or in drupal 6 in settings.php in default directory check

$db_url = 'mysql://username:password@localhost/databasename';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.