Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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
1  
Hello, and welcome on Drupal Answers. May you show the code you are using on test.php? –  kiamlaluno Sep 10 '12 at 23:09
add comment

3 Answers

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! –  vertoe Oct 7 '13 at 8:57
add comment

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']     = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD']  = 'GET';
$_SERVER['QUERY_STRING']    = '';
$_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.