Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Hello, and welcome on Drupal Answers. May you show the code you are using on test.php? – kiamlaluno Sep 10 '12 at 23:09

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.

share|improve this answer
This is just awesome, thanks! – 5chdn Oct 7 '13 at 8:57

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';
share|improve this answer

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';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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