Connection timed out when trying to connect to MySQL database with PHP


I am having trouble connecting to my MySQL databases using PHP. To begin, when I first try to establish connection to the database, the connection is remarkably slow. Then anytime I try to make a query (in this case, I’m trying to Insert into one of my tables), I get the Connection failed: Connection Timed Out.

    $check = getimagesize($_FILES["image"]["tmp_name"]);
    if($check !== false){
        $image = $_FILES['image']['tmp_name'];
        $imgContent = addslashes(file_get_contents($image));

        $dbHost     = 'sql***';
        $dbUsername = 'epiz_user';
        $dbPassword = 'password';
        $dbName     = 'epiz_user_table';
        $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
            die("Connection failed: " . $db->connect_error);
        $dataTime = date("Y-m-d H:i:s");
        $insert = $db->query("INSERT into testing (image, created) VALUES ('$imgContent', '$dataTime')");
            echo "File uploaded successfully.";
            echo "File upload failed, please try again.";
        echo "Please select an image file to upload.";


I just checked your website, but I see a different error:

 Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'epiz_user'@'192.168.0.XX' (using password: YES) in XXX

I checked your account and it looks like you’re not using the right password. Please make sure to use your hosting account password, not the client area password.


The database info that I used in my code is not the actual credentials for my database, so I don’t believe that is the problem. Like I said, I’m able to establish connection with the database fine, queries will not work however.


The message Connection Timed Out implies that there is a problem establishing a connection to the database, before authentication happens (let alone executing any actual queries). My first guess would be you’re using the wrong MySQL hostname.

closed #5