hostname = $hostname; $this->port = $port; $this->username = $username; $this->password = $password; $this->dbname = $dbname; // connect to the DB if (!$this->connect()) { // $this->dblink is FALSE here, so we cannot call mysqli_error() on it. // Use mysqli_connect_error() and show a friendly, actionable message. $error = mysqli_connect_error(); die("Database connection failed: " . htmlspecialchars( $error !== null && $error !== '' ? $error : 'could not connect to the database server. Please check the host, port and credentials. (When running with Docker, the database host is usually "db", not "localhost".)' )); } // we will operate in UTF8 mysqli_query($this->dblink,"SET NAMES 'UTF8'"); } }; // database is not needed if we're displaying static pages $req_file = basename($_SERVER['PHP_SELF']); if (!in_array($req_file, ['tutorial.php', 'anleitung.php'])) { $database = new MYSQLi_DB(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB, (defined('SQL_PORT') ? SQL_PORT : 3306)); $link = $database->return_link(); $GLOBALS['db'] = $database; $GLOBALS['link'] = $database->return_link(); // register all functions to be executed when the script is over, // so we can flush any SQL caches we may still have pending register_shutdown_function(function() { global $database; $database->sendPendingMessages(); }); } ?>