I've found lots of posts about this database connection error, but none similar to my current problem. Here's what happens.
On my localhost machine I have installed a few moodle sites to conduct my tests. I rarely use the "Run now" feature in the Scheduled Tasks. I only use it when I create a new Moodle install, in order to "Download available H5P content types from h5p.org". That's what I was trying to achieve yesterday on a new install, and I got the "Error: Database connection failed" message! Actually I get that error message for any task I try to "Run now", not just getting the H5P content types.
What is strange is that I have a very similar local Moodle site, where I never get such error. I have checked my databases, config file, etc. they are both ok, but I can't get rid of the error on my new install.
Running Windows 11 Wampserver with Apache/2.4.51 (Win64) PHP/8.1.13 MySQL Version:8.0.27. Trying to install Moodle 4.3.2 (Build: 20231222) from github. I can provide more info if needed.
Any hints welcome!
PS.- As a workaround, I can manage to run the "Download available H5P content types from h5p.org" task using CLI. But not the best option.