问题描述
我正在运行php页面从命令行更新mysql db一旦php exec命令完成。
但是,我刚刚重新安装了我的服务器,现在脚本在命令行运行时返回以下错误:
致命错误:调用未定义函数mysql_connect()
脚本在浏览器中运行良好,这意味着mysql安装完成。 如何在命令行中启用PHP中的mysql?
非常感谢。
首先,您可以使用
php -m
从命令行检查启用了哪些扩展。
如果mysql不在列表中,则意味着它未启用/加载 - 这可能是这种情况。
然后,您要使用
php --ini
以检查哪些
.ini
文件已由PHP读取。
一旦你找到了使用了php.ini
的文件,编辑它,并添加如下:;配置php MySQL模块
extension = mysql.so
加载
mysql
扩展。
根据您的发行版本,可能是。 ini
每个扩展程序文件(例如,Ubuntu就是这样)。
如果是这样,创建一个新的
.ini
文件(例如mysql.ini
),我发布到该新文件。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 usephp --ini
to check which
.ini
file(s) is/are read by PHP.
Once you've found out whichphp.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.这篇关于命令行PHP mysql_connect()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!