0

Warning: mysqli::__construct(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

try{   
    $mysqli = new mysqli('cpanelhost','cpanel_db_user','cpanel_db_password','cpanel_db','port');
    if ($mysqli -> connect_errno) { 
        echo "Failed to connect to MySQL: " . $mysqli ->connect_error;
        exit();      
    } 
    $sql = "INSERT INTO table (column1, column2) VALUES ('value1', 'value2')";                    
    $mysqli->query($sql) ;      
    $mysqli->close();
}
catch(Exception $e){
    $mysqli->close();
    return $e;  
}
0

1 Answer 1

1

I would highly recommend you to:

  1. Ask your hosting provider if they ALLOW remote MySQL connections.
  2. Ask your host if port 3306 is open.

If the above is covered, then you will need to:

  1. Add the IP address of the remote machine ( where you are trying to establish this connection ) to "Remote MySQL" in cPanel.
  2. Use your server's hostname or IP as the MySQL Host in your connection configuration.

And if you still cannot establish a successful connection, I would recommend switching to a managed hosting provider which fully supports remote MySQL connections.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.