PHP命令行mysqli的工作,但不能在页面上 [英] PHP mysqli works in command line, but not on pages

查看:362
本文介绍了PHP命令行mysqli的工作,但不能在页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Red Hat Linux的服务器,Apache 2.2的,PHP 5.5.4

Red Hat Linux Server, Apache 2.2, PHP 5.5.4

当我在命令行中运行它,一切似乎是罚款:

When I run this in the command line, everything seems to be fine:

PHP -r'$的mysqli =新的mysqli(127.0.0.1,取消,私服,事,3306);

php -r '$mysqli = new mysqli("127.0.0.1", "un", "pw", "things", "3306");'

与此同时,我有一个不运行的.php文件。我得到这个错误...

At the same time, I have a .php document which doesn't run. I get this error...

PHP致命错误:类'mysqli的在[/path/to]/vars.php找不到第2行

PHP Fatal error: Class 'mysqli' not found in [/path/to]/vars.php on line 2

从这个code:

<?php
    $mysqli = new mysqli("localhost", "un", "pw", "things", "3306");
?>

其他的.php页面(不使用的mysqli)做工精细。任何想法是怎么回事?先谢谢了。

Other .php pages (which don't use mysqli) work fine. Any idea what's going on here? Thanks in advance.

推荐答案

从CLI(命令行)运行PHP是Web服务器deffent。

running php from CLI(command line) is deffent from webserver.

Ushould能够在这两个mysqli扩展。

Ushould enable mysqli extension in both.

通常情况下,如果已安装,你可以进入的php.ini,并取消了mysqli的行了。在一些设施,有一个Apache的php.ini文件的一个副本,另一个用于命令行。我认为它们都位于在某处的/ etc / PHP5 /'.

Normally, if it is installed, you can go into 'php.ini' and uncomment the line for 'mysqli'. On some installations, there is one copy of 'php.ini' for Apache and another for the command line. I think they are both located somewhere under '/etc/php5/'.

这篇关于PHP命令行mysqli的工作,但不能在页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆