简体   繁体   中英

Fatal error: Call to undefined function mysql_connect() in

When I call this command:

php.exe Connection.php

I get this error:

Fatal error: Call to undefined function ...\mysql_connect() in Connection.php on line x.

But if I run it in my browser on the same server I have no problem. And yes, mysql is enabled on my server

[EDIT] Complete error:

"C:\Program Files (x86)\EasyPHP-5.3.6.0\php\php.exe" "C:\Program Files (x86)\EasyPHP-5.3.6.0\www\MusicSite\Php\Devtron\Exemples\NewsTable.php"

Fatal error: Call to undefined function Devtron\Database\mysql_connect() in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\MusicSite\Php\Devtron\Database\Connection.php on line 108

The command line interpreter does not necessarily load the same configuration file as whatever SAPI you've configured in your web server. Run this to find out:

<?php

var_dump( php_ini_loaded_file() );
var_dump( php_ini_scanned_files() );

Sounds almost like there are two instances of PHP on the server. This can happen if you install PHP (which is available from shell by default) and then someone installed a package like xampp. I'd take a look through the server's filesystem (maybe a find / -name "php.exe" ) to locate all instances.

Sounds like the one running on the web server has mysql enabled, but the one running in shell doesn't.

Try this

$ php -m

check mysql is listed in the list or not.

$ php --ini 

if out put as like this

Configuration File (php.ini) Path: /usr/local/lib

Loaded Configuration File:         (none)

Scan for additional .ini files in: (none)

Additional .ini files parsed:      (none)

$ locate php.ini then there is php5 on your system.

 /etc/php5/apache2/php.ini
 /etc/php5/cli/php.ini
 .....................
 .....................

Now do nothing use php5 instead of php as like this.

$ php5 test.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM