It was not possible to connect: no connection could be made because the target machine actively refused them
I'm trying to connect to my database. This is easyphp webserver 14.1.
Follows the php code for connection.
<?php
$HOST = '10.40.0.185:3388';
$USER= '*****'; // Aqui informei o usuário do meu banco
$PASS= '*****'; // Aqui informaei a senha do usuário para acesso ao banco
$BANCO = 'gclient_embratel';
$conexao = mysql_connect($HOST,$USER,$PASS) or die('Não foi possivel conectar: '.mysql_error());
$selecao = mysql_select_db($BANCO);?>
1 answers
Answer:
Since you are using the database on the same machine as the application, the database connection setting can be changed to:
<?php
$HOST = 'localhost:3388';
$USER= '*****';
$PASS= '*****';
$BANCO = 'gclient_embratel';
$conexao = mysql_connect($HOST,$USER,$PASS) or die('Não foi possivel conectar: '.mysql_error());
$selecao = mysql_select_db($BANCO);?
?>
Instead of the IP of your external machine defined in the variable $HOST
I put the value localhost
, but it could be used also 127.0.0.1
.
How Much The refused connection can occur by several factors, the main ones being:
The MySQL database service does not it started and is not running on Port 3388. If you use Linux you can do the
fuser 3388/tcp
command to check if there is a process using this port.There is some restriction in your machine's firewall to Port 3388.
Are you using a
Amazon Web Services
machine for your application? You must release the port in the security settings of your instance.
Putting the value localhost
in the variable $HOST
probably the options 2
and 3
are discarded because Port 3388 of the local machine will be accessed without the need for external access.