为什么PHP卡在mysqli_connect上而没有错误代码?

时间:2019-03-23 06:26:09

标签: php linux mysqli apache2 mariadb

在线

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

PHP停止运行,没有错误。

这是用于运行PHP 7.0,Apache 2和MariaDB 10的新Linux服务器。即使安装了“ mysql-server”软件包,我也不知道为什么要运行MariaDB。我读到它们是兼容的,所以我认为应该没问题。我尝试在另一台计算机(Raspberry Pi 3)上设置服务器,但结果相同。

<?php

$dbServername = "localhost";
echo "passed dbServername <br>";
$dbUsername = "root";
echo "passed dbUsername <br>";
$dbPassword = "";
echo "passed dbPassword <br>";
$dbName = "cities";
echo "passed dbName <br>";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
echo "passed conn <br>";

if (!$conn) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
} else {
    echo "success! <br>";
}
?>

这是我的网页输出的内容:

passed dbServername
passed dbUsername
passed dbPassword
passed dbName 

绝对没有别的。无论连接与否,我都希望会有更多输出。

编辑:

有趣的是,如果我插入如下错误报告:

$dbServername = "localhost";
echo "passed dbServername <br>";
$dbUsername = "root";
echo "passed dbUsername <br>";

mysqli_report(MYSQLI_REPORT_ALL);

$dbPassword = "";
echo "passed dbPassword <br>";
$dbName = "cities";
echo "passed dbName <br>";

我得到输出:

passed dbServername
passed dbUsername 

因此,似乎通过添加与MySqli相关的任何内容都会冻结PHP。

没有错误报告,当我查看源时显示:

passed dbServername <br>passed dbUsername <br>passed dbPassword <br>passed dbName <br>

1 个答案:

答案 0 :(得分:0)

我知道这是7个月大了,但是我遇到了同样的问题。

我的解决方案很简单: 我还没有安装php-mysql!

在Ubuntu中运行

apt install php-mysql