I try to connect to my database that I have in my Mysql Workbench from my php application. I have already connected to this database from my other Java application, using JDBC, like following:
public class TestConnect {
    static String USERNAME = "root";
    static String PASSWORD = "mypassword123";
    static String CONN_STRING = "jdbc:mysql://localhost:3306/sources?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
    static Connection CON = null;
    
    public static void main(String[] args) throws SQLException, IOException, ParserConfigurationException, SAXException {
        Connection con = null;
        try {
            con = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
            CON = con;
        } catch (SQLException e) {
            System.err.println(e);
        }
    }
}
This works. Now I want to connect to the same database from my website, that I'm creating using php. So what am I trying so far is the following:
database.php
<?php
$host = 'localhost';
$username = 'root';
$password = 'mypassword123';
$dbname = 'testDB';
$mysqli = new mysqli($host,$username,$password,$dbname);
if ($mysqli->connect_errno) {
    echo '<strong>Could not connect to server.</strong>';
} else {
    $mysqli->query("SET CHARACTER SET 'utf8'");
}
However, when I open my website (on localhost), I only get 'Bad Gateway' warning. Can you tell me what I'm doing wrong or what am I missing?
