Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

339
Visualizações
mysqli connection attempt failed after about 20 seconds

I'm trying to set up a web server at home, using XAMPP v3.2.2, running on a 32-bit Windows 10 tablet.
It has:
- Apache/2.4.38 (Win32)
- PHP Version 7.3.2
- mysql Ver 15.1 Distrib 10.1.38-MariaDB, for Win32 (AMD64)

The DNS setting for my domain include an A record, pointing to my external (ISP assigned, and the same for years) IP address, both for www.mydomain.mytld and for @.mydomain.mytld.

Port forwarding for port 80 to the server has been set up in my router.

The Apache's httpd.conf file includes a section:

<VirtualHost *:80>
    ServerName www.mydomain.mytld
    ServerAlias *.mydomain.mytld
</VirtualHost>

In MySQL, database user username has SELECT, DELETE, INSERT and UPDATE privileges for the database accessed from localhost.

In the .php file I connect to the database using:

$dbUrl = "127.0.0.1";
$dbUser = "username";
$dbPass = "password";
$dbName = "database";
$db = new mysqli($dbUrl, $dbUser, $dbPass, $dbName);

This works fine when I access this on the server itself (using http://127.0.0.1/).
It also works fine when I access the same from another computer in the home network using the server's network address (http://192.168.178.35/).
It also works fine when I access the same from another computer in the home network using my external (ISP assigned) IP address.

But ... when I try the same using my domain name it fails: "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." at the $db = new mysqli(... statement.

I've tried localhost and even the server's network address (192.168.178.35) for $dbUrl, and also tried including the port number 3306, all to no avail.
Tried the root user with all privileges too, results are still the same.

Other pages on the same server (both .html and .php) that do not use the database, do work fine using my domain name.

Somewhere on the internet I found maybe this could be solved by commenting out (with a #) the ::1 localhost line in the %WINDIR%\system32\drivers\etc file, but that line is already commented out in my hosts file.

Since everything works fine using my external IP address, just not using my domain name, I expect I'm simply missing some directive(s) somewhere in one of the many configuration files, but I can't find what I'm missing.

Any ideas, anyone?
Thanks in advance.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I've found the problem.

Stupid me oversaw some obsolete code that altered the $dbUrl variable value, based on the $_SERVER["SERVER_NAME"] information, between the assignment statement and the creation of the mysqli object. I've deleted the old code and now it functions perfectly.

Thank you all, who took the time reading this problem and sorry for wasting your time.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda