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


#1

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.

<?php
if(isset($_POST["submit"])){
    $check = getimagesize($_FILES["image"]["tmp_name"]);
    if($check !== false){
        $image = $_FILES['image']['tmp_name'];
        $imgContent = addslashes(file_get_contents($image));

        $dbHost     = 'sql***.epizy.com';
        $dbUsername = 'epiz_user';
        $dbPassword = 'password';
        $dbName     = 'epiz_user_table';
        
        $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
        
        if($db->connect_error){
            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')");
        if($insert){
            echo "File uploaded successfully.";
        }else{
            echo "File upload failed, please try again.";
        } 
    }else{
        echo "Please select an image file to upload.";
    }
}
?>

#2

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.


#3

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.


#4

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