[wp-trac] [WordPress Trac] #58347: Error establishing a database connection when siteurl and home are set to null

WordPress Trac noreply at wordpress.org
Thu May 18 03:37:06 UTC 2023


#58347: Error establishing a database connection when siteurl and home are set to
null
----------------------------+-----------------------------
 Reporter:  alexstandiford  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Database        |    Version:  6.2.1
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58347>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list