问题描述
我正在使用Ubuntu LTS 14.04操作系统,并且试图在PHP CLI中测试我的PHP脚本,但是无论我的代码尝试使用诸如...
I'm using Ubuntu LTS 14.04 operating system and I'm trying to test my PHP scripts in the PHP CLI, but wherever my code attempts to connect to MySQL, with commands such as...
$mysqli = mysqli_connect($host,$user,$password,$database);
...,出现以下错误:
...,I get the following error:
Fatal error: Call to undefined function mysqli_connect()...
我已经审查了/etc/php5/cli/php.ini
和/etc/php5/apache2/php.ini
,但没有发现任何区别.
I've reviewed /etc/php5/cli/php.ini
AND /etc/php5/apache2/php.ini
and have found no difference.
我认为必须为命令行界面(CLI)启用mysqli支持,但是我不确定.
I think that I must enable mysqli support for the command line interface (CLI), but I am uncertain.
如何在不影响当前Apache php.ini/configuration/installation的情况下更正错误?
How can I correct the error without affecting my current Apache php.ini/configuration/installation?
编辑:
基于注释,我在终端中运行了以下命令:
EDIT:
Based on comments, I ran the following command in terminal:
php --ini
哪个显示:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
然后,我将/etc/php5/cli/php.ini
复制到/usr/local/lib/php.ini
.
然后,我再次运行 php --ini
,它显示:
Then, I ran php --ini
again, which displays:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
然后,我再次从PHP CLI运行了PHP脚本,并显示了相同的错误.
Then, I ran the PHP script from PHP CLI again, and the same error displayed.
推荐答案
表示未加载mysqli扩展.
Means the mysqli exension is not loaded.
如果它们相同的话,我会感到非常惊讶.但是在这两种情况下,它们很可能都可以与通过软件包分发的扩展一起使用-即,包含用于加载mysqli的指令的ini文件,因此扩展名很可能位于其他地方,并且可以(或不可以)包含在这些文件中.
I would be very surprised if they were same. But in both cases, these are likely to be structured to work with extesnions distributed via packages - i.e. the ini file containing the directive to load the mysqli so extension will likely reside elsewhere and be included (or not) from these files.
您有科学怪人系统.您需要清理.使用发行版的打包应用程序或从tarball安装应用程序.除非您知道自己在做什么,否则不要使用tarball.除非您真的知道自己在做什么,否则不要混搭.
You have a Frankenstein system. You need to clean this up. Either use the distro's packaged apps or install apps from tarball. Don't use tarballs unless you know what you're doing. Don't mix and match unless you really know what you are doing.
- 删除tarball PHP文件
- 重新安装Ubuntu PHP cli
- 重新安装Ubuntu PHP mysqli扩展
这篇关于如何为PHP的CLI启用mysqli支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!