Jump to content

Strange silent error while connecting to DB


TomPich
 Share

Recommended Posts

Hello guys,

I have a strange and silent error on a PW website that I cannot figure out.
It happens only online (not in local).
It’s a database connexion error, and I never saw it on the website, it just appears in the logs.

On localhost, the url is mfw-ut-inscription-2024. It’s a different one online, of course.
I have my credentials for databases (internal and external databases) in config.php, which look like:

// PW database
if ( in_array($_SERVER["HTTP_HOST"], ["my-distant-website.com"])) {
    $config->dbName = 'xxx';
    $config->dbUser = 'xxx';
    $config->dbPass = 'xxx';
} else {
    $config->dbName = 'xxx';
    $config->dbUser = 'root';
    $config->dbPass = '';
}

// External database
if ( in_array($_SERVER["HTTP_HOST"], ["my-distant-website.com"])) {
    $config->gestiondbName = 'xxx';
    $config->gestiondbUser = 'xxx';
    $config->gestiondbPass = 'xxx';
} else {
    $config->gestiondbName = 'xxx';
    $config->gestiondbUser = 'root';
    $config->gestiondbPass = '';
}

Everything works perfectly. But every day, I get new errors logged in the errors.txt log file (from the online website).

2024-11-10 12:41:56    ?    https://mfw-ut-inscription-2024/
Error:  Exception: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
    (in /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireDatabasePDO.php line 505)
#0 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireDatabasePDO.php(505): PDO->__construct()
#1 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireDatabasePDO.php(872): ProcessWire\WireDatabasePDO->pdoWriter()
#2 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireSaveableItems.php(219): ProcessWire\WireDatabasePDO->prepare()
#3 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Wire.php(416): ProcessWire\WireSaveableItems->___load()
#4 /home/joko4944/domains/staging.ut-inscription.com/wire/core/WireHooks.php(968): ProcessWire\Wire->_callMethod()
#5 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Wire.php(484): ProcessWire\WireHooks->runHooks()
#6 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Fields.php(285): ProcessWire\Wire->__call()
#7 /home/joko4944/domains/staging.ut-inscription.com/wire/core/Fields.php(172): ProcessWire\Fields->getWireArray()
#8 /home/joko4944/domains/staging.ut-inscription.com/wire/core/ProcessWire.php(625): ProcessWire\Fields->init()
#9 /home/joko4944/domains/staging.ut-inscription.com/wire/core/ProcessWire.php(578): ProcessWire\ProcessWire->initVar()
#10 /home/joko4944/domains/staging.ut-inscription.com/wire/core/ProcessWire.php(315): ProcessWire\ProcessWire->load()
#11 /home/joko4944/domains/staging.ut-inscription.com/index.php(52): ProcessWire\ProcessWire->__construct() #12 {main}

So that’s very very strange because:
(1) the url is *not* the url of the online website (although the errors only show up online).
(2) at some point, PW tries to connect to my local databases (and of course it can’t, because it’s online)
(3) I never noticed anything wrong on the onine website, nor my client...

The local url (mfw-ut-inscription-2024) only appears at 4 places in the website files:
Three times in config.php
• $config->httpHosts = array('mfw-ut-inscription-2024', "my-distant-website.com");
• twice in something like: if ($_SERVER["HTTP_HOST"] === 'mfw-ut-inscription-2024' ){/* some scret keys for some services */}

and one last time in a hook in init.php: $is_local = $this->config->domain === "mfw-ut-inscription-2024";

So I can’t understand how the online website can detect a session @ https://mfw-ut-inscription-2024/.
Can this be due to some cache file? I only use the basic cache system of PW and no template is cached.

Any clue or advice would be welcome. 😊
Thank you

Link to comment
Share on other sites

I think I got it.
I use Stripe on this website. And to confirm webhook, there is a POST request sent by Strip to confirm payment.
When I do a test on the local website, Stripe sends the request to the online website, but with a reference to the local url...
So PW cache is not involved here, I guess...

Link to comment
Share on other sites

  • 2 weeks later...

OK, so it’s not Stripe.

Every now and then, specialy in the middle of the night, I have the following exceptions logged:

2024-11-24 01:25:55    ?    ?    Unable to load Modules - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (in /wire/core/WireDatabasePDO.php line 505)
2024-11-24 01:25:55    ?    ?    SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (in /wire/core/WireDatabasePDO.php line 505)

Somehow, PW wants to use the local db credencial, even though it’s the online website. No error has been reported by my client, and I can’t see no error neither.
Any clues about what this is about?

Any help would be really appreciated.

Thanks

Link to comment
Share on other sites

On 11/10/2024 at 6:01 PM, TomPich said:
if ( in_array($_SERVER["HTTP_HOST"], ["my-distant-website.com"])) {

I don't know if that could be the reason, but I don't use the host at all any more in my config files. I always use the concept of including different files on my local development and on remote servers. See here:

One of the reasons is that the hostname (or in your case the HTTP_HOST variable) might not be available. For example when bootstrapping or calling it from a cronjob. Or the variable might be empty for whatever reason. When including different config-local.php files on local dev and on production/staging you don't have these problems.

That would at least be something that you can try.

 

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...