PHP:mysql_connect()无法通过命令行运行 [英] PHP: mysql_connect() won't work via command line
问题描述
我有一个脚本,该脚本调用mysql_connect()
连接到MySQL数据库.当我在浏览器中运行脚本时,它可以工作.但是,当我从命令行运行它时,出现以下错误:
I have a script which calls mysql_connect()
to connect to a MySQL DB. When I run the script in a browser, it works. However, when I run it from a command line I receive the following error:
Call to undefined function mysql_connect()
这似乎完全是自相矛盾的.任何人都有我如何从命令行运行它的想法.顺便说一句,我是从bash shell运行它的,像这样:
This seems completely paradoxical. Anyone have any ideas as how I can run it from the command line. Btw, I run it from a bash shell like so:
php /path/to/script.php
推荐答案
它可能使用默认的PHP配置.我之前发现它不使用相同的php.ini或根本不使用一个.因此,某些扩展将不会启用.
It maybe using a default PHP configuration. I have found before that it doesn't use the same php.ini or doesn't use one at all. Therefore some of the extensions won't be enabled.
相反,请执行以下操作:
Do this instead:
php -c /etc/php.ini /path/to/script.php
/etc/php.ini
是ini文件的路径.您可以通过执行phpinfo();
Where /etc/php.ini
is the path to your ini file. You can find this by doing a phpinfo();
这篇关于PHP:mysql_connect()无法通过命令行运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!