0

I'm trying to run a php script from the command line via Drush. When I tried to use EntityFieldQuery...

$query = new EntityFieldQuery;

I got the error:

PHP Fatal error:  Class 'EntityFieldQuery' not found in /path/to/my/script.php on line 43

So, I tried to make it even simpler, and just used this script:

<?php

print "inside script\n\n";
$user = user_load(1);
print "name: ".$user->name;

?>

But I get the error:

PHP Fatal error:  Call to undefined function user_load() in /path/to/my/script.php on line 17

It doesn't appear that drush is bootstrapping properly. Am I missing something? What do I need to do for drush to be able to use the drupal apis?

I read through Drush php-script | Drupal functions such as node_load() are not being found, but I've got mysql client libraries already installed so that isn't a solution for me.

0

Ok, WOW, 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 regranted 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
    3 years later I just had this problem again and Google searched to find out what was going wrong, found this incredibly helpful suggestion, and tried to upvote it... and StackOverflow told me I wasn't allowed to upvote my own answer. And that's when I realized -I- had posted this question and answer. /facepalm heh. – Kenny Wyland Jan 21 '18 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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