Make WordPress Core

Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#58347 closed defect (bug) (duplicate)

Error establishing a database connection when siteurl and home are set to null

Reported by: alexstandiford's profile alexstandiford Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.2.1
Component: Database Keywords:
Focuses: Cc:


With the siteurl and home settings set to "NULL" in the database, the site shows "Error establishing a database connection" with no indication on what the actual problem is.

This might also be because the siteurl and home constants were set in my wp-config file, but I'm really not sure if that's related or not.

What I expected was to get a more useful error message that would more-accurately reflect the actual problem, since it was definitely not an error establishing a database connection. It could have saved me several hours.

Here's the context on what happened:

I was tinkering with the settings, and while on the general settings page, I happened to click "save" without making any changes to the page, and for some reason that changed the siteurl and home value into something it wasn't supposed to be. This caused the site to stop working properly. To fix the problem, I added the const values in my wp-config file to force the setting to the correct value.

The next morning, I wake up to find that I'm getting a vague "Error establishing a database connection" error on the site. I spent some time looking through the usual channels to figure out the cause of the issue, and everything kept pointing me back to "the database is credentials are effed up". Which made no sense, since I was literally just using this site yesterday.

What made it more confusing, was that I was able to access the site using WP-CLI with no problem. I was also able to access the database using TablePlus. So I knew there shouldn't be an "error establishing a database connection" since I was clearly able to, ya know, establish a database connection.

After a few hours of trying all kinds of things, from disabling plugins, to changing themes, restoring backups, spinning up a whole new site, running the WordPress repair utility (which told me the database was perfectly healthy!) and even changing which database the site connects to, I finally concluded that it was absolutely, positively, 100% certainly not an issue with a database connection.

I started to arbitrarily dump data in the core files, hoping that maybe I could get a more-useful error message, and none of my loggers were giving me any information on why I was getting the error. And came up short. $wpdb didn't provide any useful errors, and that includes last_error. All I could get was the "one or more tables was missing" errors

I reminded myself that computers rarely just break for no reason, and that it has to somehow be related to what I had done yesterday when I was messing with the settings, so I retraced my steps in the database using TablePlus, and found the siteurl and home options. I noticed they were set to null, so on a whim I changed them to the correct value.

And this fixed the problem.

Change History (1)

#1 @SergeyBiryukov
14 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac! Thanks for the ticket.

Just to clarify, this happens because is_blog_installed() specifically checks if the 'siteurl' option is not empty as the way to determine if a site has been installed, probably because that is the first option created during installation.

We're already tracking this issue in #29794, let's continue the discussion there.

Last edited 14 months ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.