Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to run a PHP script from the command line, but get the following error:

Call to undefined function mysql_connect()

However, the mysql module is loaded:

root /var/www/scripts # php -m | grep mysql

I am on a Debian machine, so all modules are being loaded in their own .ini file:

root /var/www/scripts # php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/10-pdo.ini,

So even though the mysql module has been loaded, I still get said error when trying to call mysql_connect() in the PHP script.

Any ideas?

PS: Running the script via Apache works fine.

share|improve this question
Did you have a look to your php error log file to look for additional information? – jap1968 Jun 1 '13 at 15:38
No information in error log, since I run the script from command line. – Matthias Jun 2 '13 at 1:38
up vote 0 down vote accepted

A solution to this problem seems to be both easy and strange (?) alike:

php -c /etc/php5/cli/php.ini -nf script.php

Why do I have to specify the php.ini file on command line again, if the interpreter says it loads that ini file anyway, even when one does not specify it explicitly?

share|improve this answer
You probably have two different versions of PHP installed on your system. – Michael Hampton Jun 3 '13 at 0:31

Your Answer


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.