Error connecting php to Mysql - Connection failed: No route to host

Asked

Viewed 51 times

-2

Hello I have a php site where he accesses the Mysql database everything worked perfectly until today the afternoon when out of nowhere he started to bring me the error whenever he tries to access mysql Connection failed: No route to host, did not touch anything in the code and it keeps giving error, the same code accesses other servers without problem by the same site but only this server does not work, I do not know what to do a detail if I run php from another machine with an ip other than mine it works normal to access the server. I do not know if there is something blocking. the server I am accessing is not local follows here an example of my code

<?php

$host = "123.123.123.123:5600";
$user = "abc";
$pass = "123456";
$base = "tec";

$mysqli_connection = new MySQLi($host, $user, $pass, $base);
if($mysqli_connection->connect_error){
   echo "Desconectado! Erro: " . $mysqli_connection->connect_error;
}else{
   echo "Conectado!";
}
?>

Help me do not know what else I can do, I just have problems on a server in specific the rest is normal

2 answers

-1

I believe that if using PDO there will be more chances to work, try changing to port 127.0.0.1 and see if it works, after this check if the server 123 is correctly declared.

<?php
$dsn = "mysql:host=127.0.0.1;dbname=tec";
$root = "abc";
$password = "123456";

$con = new PDO($dsn,$root,$password) OR DIE ('Erro na conexão!');

if($con){
   //code...
}
else {
   //code...
}
?>
  • The server is not local as mentioned in the advertisement

  • Take a look at this question: https://stackoverflow.com/questions/57001170/mysql-connection-failed-no-route-to-host if it is a similar problem.

  • If you are using Linux try this path: https://www.maketecheasier.com/fix-no-route-to-host-error-linux/

-2

The problem does not seem to be in your code, but in the SQL server or in some intermediary.

  1. Check if the service is running
  2. Check if the port number is correct or if the firewall is blocking the port
  3. Check if your computer can access the ip (use a ping to check this)
  4. If you have a router halfway through, check the router firewall or the port Forwarding

hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.