建立mysqli连接时PHP脚本没有响应

马库斯

我只需要一个从 php-Script 调用的简单 mysqli-Connection。以下脚本没有响应。如果出现某种错误消息,甚至是一些用于调试目的的回声语句,会更容易。但不是。只有白屏。

<?php
private $db_config_file = realpath(dirname(__FILE__)) . "config/db.ini";
    private $db = NULL;
    if (!file_exists($this->db_config_file)) {
    $msg = "The config-file <code>" 
        . $this->db_config_file 
        . "</code> doesnt't exist.";
    show_error_page($msg);
}

$config = parse_ini_file($this->db_config_file);
$host = $config[$host];
$user = $config[$user];
$password = $config[$password];
$dbname = $config[$dbname];

$conn = new mysqli($host, $user, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else echo "Connection established!";

$conn->close();
?>

db.ini:

host = localhost
dbname = bl
user = mm
password = noadmin 
马赫什·赫格德

尝试改变

$host = $config[$host];
$user = $config[$user];
$password = $config[$password];
$dbname = $config[$dbname];

$host = $config['host'];
$user = $config['user'];
$password = $config['password'];
$dbname = $config['dbname'];

你正在使用 $host = $config[$host],它需要是 $config['host']

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章