Jump to content

using PW via command line interpreter include


Recommended Posts

I run php -a so I have an interactive shell to work with. I've tried to include('./index.php'); per the instructions at https://processwire.com/api/include/ but I get the following error:

Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in /.../wire/core/WireDatabasePDO.php on line 83.
Any ideas? Will it just not work in the interactive shell?
Link to comment
Share on other sites

Run "php -i" from the command line. It will list all installed modules, and even more, it will give you the location of the php.ini file used by the php cli - it's not neccessarily the same as your webserver module uses. So on linux, running

php -i | grep php.ini

or on windows

php -i | findstr php.ini

will give you a line reading "Loaded Configuration File => PATH/TO/php.ini". Make sure that this file also loads all required modules.

It might also be worth it to make sure that the php executable you start in fact belongs to the same installation as the library loaded into the webserver. With the popularity of bundles like [X|W|L|M]AMP I've often seen the path still pointing to outdated older php installations while the server used a far newer version.

  • Like 3
Link to comment
Share on other sites

Thank you! (And I never even mentioned this was my first PHP project as well - maybe it was obvious.) I left out a few details that I'll fill in, but this let me find the issue.

I'm running Ubuntu 14.04 LTS, 64-bit, with MariaDB, nginx, and PHP5. Ubuntu has a nasty habit of creating their own versions of builds for almost everything mostly due to the way they like things to be configured. In order to get readline support to begin with (the Ubuntu standard version didn't ship with it) I had to build PHP from sources. So I now have two different versions of PHP installed - one in /usr/bin and another in /usr/local/bin. And as you noted, they both use different php.ini files.

It turns out the the command line php reference is more recent, but has an empty php.ini file.

It's easier for me just to run the same one as the server even though Ubuntu has now updated their cli version to include readline support.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...