Unable to connect: No connection could be made because the target machine actively refused them

0

I'm trying to connect to my database. This is easyphp webserver 14.1.

Followthephpcodeforconnection.

<?php$HOST='10.40.0.185:3388';$USER='*****';//Aquiinformeiousuáriodomeubanco$PASS='*****';//Aquiinformaeiasenhadousuárioparaacessoaobanco$BANCO='gclient_embratel';$conexao=mysql_connect($HOST,$USER,$PASS)ordie('Nãofoipossivelconectar:'.mysql_error());$selecao=mysql_select_db($BANCO);?>

Thefollowingerrormessageisdisplayed:

    
asked by anonymous 29.09.2016 / 00:12

1 answer

1

Answer:

Since you are using the database on the same application machine, the database connection configuration 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 could also be used 127.0.0.1 .

How much the refused connection can occur by several factors, the main ones being:

  • The MySQL database service did not start and is not running on port 3388. If you use Linux you can do the fuser 3388/tcp command to check for a process using that port.

    / li>
  • There are some restrictions on your machine's firewall for port 3388.

  • Are you using a Amazon Web Services machine for your application? You need to release the port in the security settings of your instance.

  • By setting the localhost value to the $HOST variable, the 2 and 3 options are probably discarded because port 3388 on the local machine will be accessed without external access.

        
    29.09.2016 / 00:44