問題描述
我正在嘗試使用 Apache 2.4.7 作為 Web 服務器連接 PHP 5.4.22 和 MySQL 5.5.所有這三個單獨工作正常.但是,當我嘗試將 PHP 與 MySQL 連接時,出現錯誤:
I am trying to connect PHP 5.4.22 and MySQL 5.5 with Apache 2.4.7 as the web server. All three of these individually are working fine. However, when I try to connect PHP with MySQL I get the error:
致命錯誤:調用未定義的函數 mysqli_connect() in..."
"Fatal error: Call to undefined function mysqli_connect() in..."
db_connect.php 代碼
$con = mysqli_connect("localhost","root","root","mylab_dev");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$conn->close();
httpd.conf 配置:
ServerRoot "c:/Apache24"
#Listen 12.34.56.78:80
Listen 80
LoadModule php5_module "C:/php/php5apache2_4.dll" (Verified the existence of the physical file)
AddHandler application/x-httpd-php .php
DirectoryIndex index.php index.html
PHPIniDir c:/php
修改php.ini-development文件為php.ini
Modified php.ini-development file to php.ini
; extension_dir = "./"
; On windows:
extension_dir = "ext"
extension=php_mysql.dll --> Uncommented
extension=php_mysqli.dll --> Uncommented
相應地設置日期時區
我注意到一件事,但不確定這是否是原因,在 phpinfo()
頁面中,我看到了 MySQL 信息,但沒有看到任何顯示 mysqli() 的內容代碼>.我應該嗎?
One thing I noticed but not sure if this is the reason, in the phpinfo()
page I see the MySQL information, but I don't see anything which says mysqli()
. Should I?
推薦答案
首先,通過檢查 phpinfo()
確保您正在編輯正確的 php.ini
代碼>.
First of all, make sure you are editing the correct php.ini
by checking from the phpinfo()
.
我主要為 Windows 用戶編寫了這些說明:
I wrote these instructions mainly for Windows users:
編輯您的php.ini
.
檢查變量extension-dir
是否設置正確.如果沒有,請根據您的操作系統指定正確的路徑.
Check whether variable extension-dir
is set properly. If not, specify the correct path as per your OS.
extension_dir = "C:Program Filesphpext"
通過刪除 ;
(分號)取消注釋這些行:
Un-comment these lines by removing the ;
(semi-colon):
extension=php_mysql.dll
extension=php_mysqli.dll
這篇關于致命錯誤:在將 PHP 5.4.22 和 MySQL 5.5 與 Apache 2.4.7 連接時調用未定義的函數 mysqli_connect() in...的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!