I am running a php page form the command line to update a mysql db once a php exec command has completed. This has been working OK.
However, I have just reinstalled my server and now the script is returning the following error when I run it on the command line:
Fatal error: Call to undefined function mysql_connect()
The script runs fine in the browser which means mysql is installed OK. How do I enable mysql in PHP to be run from the command line?
Many thanks.
First of all, you can use
php -m
from the command-line, to check which extensions are enabled.
If mysql is not in the list, it means it's not enabled / loaded -- which is probably the case, here.
Then, you'll want to use
php --ini
to check which .ini
file(s) is/are read by PHP.
Once you've found out which php.ini
file is used, you'll have to edit it, and add something like this :
; configuration for php MySQL module
extension=mysql.so
To load the mysql
extension.
Depending on your distribution, the might be a .ini
file per extension (Ubuntu does that, for instance).
If that's the case, you could also create a new .ini
file (mysql.ini
for instance) next to the other ones, and put the two lines I posted into that new file.
Check the path to your PHP executable. You didn't mention which OS this is under, but, for example, under OSX just running php
executes the built-in PHP interpreter. If you're using MAMP you'll need to run /Applications/MAMP/bin/php5.2/bin/php
(or whatever your path is) to imitate what's running in your browser.
Alter the path to your web server's php accordingly (based on AMP installation, OS, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With