建立mysqli Connection时PHP脚本没有响应

时间:2017-12-09 11:21:43

标签: php mysql mysqli

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

<?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 

1 个答案:

答案 0 :(得分:2)

尝试改变

$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']