2

I successfully installed Drush on Ubuntu 12.04, and I created a script containing the following line.

print_r(node_load(10));

I am calling the script with drush php-script --uri=http://localhost myscript.php which returns the following error.

PHP Fatal error: Call to undefined function node_load()

I also tried with drush --uri=http://localhost cache-get, but I get the following error.

Command cache-get needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command.
The drush command 'cache-get' could not be executed.
Drush was not able to start (bootstrap) the Drupal database.
Hint: This may occur when Drush is trying to:

  • bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See drush topic docs-aliases for details.
  • connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details. Drush was attempting to connect to: Drupal version: 7.26
    Site URI: http://localhost
    Database driver: mysql
    Database hostname: 127.0.0.1
    Database username: username // This is shown correctly
    Database name: database_name // This is shown correctly
    PHP executable: /usr/bin/php
    PHP configuration: /etc/php5/cli/php.ini PHP OS: Linux
    Drush version: 7.0-dev
    Drush temp directory: /tmp
    Drush configuration:
    Drush alias files:
    Drupal root: /opt/lampp/htdocs
    Site path: sites/default
3
  • 3
    are you running the command from the site root folder
    – msmani
    Jun 28, 2014 at 8:07
  • Yes, I am calling drush from the site root folder. In my case that is user@computer:/opt/lampp/htdocs/sites/default$ Jun 28, 2014 at 15:56
  • If you are calling drush from the site root folder, why do you need to specify the --uri parameter? Jul 14, 2014 at 6:03

2 Answers 2

1

I finally figured out what was missing.

In my case I had to install the mysql-client-core-5.5 package with sudo apt-get install mysql-client-core-5.5.

0

I ran into the same problem (user_load() and other functions were not found), but had a different solution.

For me, it turned out that my sql privileges on the database were not correct.

I found the error by running my script with the -d option:

drush -d scr /path/to/my/script.php

I noticed in the log it spewed out that it was getting an error connecting to the database. I apparently had messed up the privs when I set them up. I sql granted the privs and my script ran just fine.

The error message about not being able to find a function was a total red herring.

1

Your Answer

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

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