-2

I just need a simple mysqli-Connection invoked from a php-Script. The following script doesn't respond. Would be way easier if some kind of error-message appears, or even some echo-statements for debugging purposes. But no. Only white screen.

<?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();
?>

The db.ini:

host = localhost
dbname = bl
user = mm
password = noadmin 
Markus
  • 93
  • 6

1 Answers1

2

try to change

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

to

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

you are using $host = $config[$host], it need to be $config['host']

Mahesh Hegde
  • 1,131
  • 10
  • 12