mysqli connection attempt failed after about 20 seconds

1 answer

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.

All answers to this question, which has the identifier 60794049

The best answer:

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.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data