My PHP script is working very well when executed via browser but showing error message when tried to execute using Command prompt.
First I tested php file from command prompt using "system('ls >/tmp/test.txt')" in php file. It worked fine.
But when executed Mysql query within PHP script via command prompt it's showing error.(note: same mysql query within php file was successfully executed from browser).
command: php fullpath____/automatic.php
error: PHP Fatal error: Call to undefined function mysqli_connect() in fullpath_____/automatic.php on line number 7.
What is the problem ?
Note that PHP may use completely different configurations for the CLI (command-line) version and the one that the webserver forwards to (for example, PHP-FPM)
That error means that the mysql extension is not enabled for PHP's CLI configuration. Login as a privileged user and try this: sudo php5enmod mysql
, after that is should work.
php command line uses diferent php.ini than php browser. You must have installed pdo_mysql extension. In linux system the command line php.ini is in
/etc/php5/cli/php.ini
And the browser php.ini is in
/etc/php5/apache2/php.ini
Check that you have in that files
extension=pdo_mysql.so
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.