I have an error with localhost about “DB_NAME”

Summary

A misconfigured WordPress installation on XAMPP triggered a PHP fatal error: the constant DB_NAME was not recognized. This happened because the wp-config.php file used invalid quotation marks, causing PHP to interpret the constant name as a malformed string rather than a defined identifier.

Root Cause

  • The define() statement used typographic (curly) quotes instead of ASCII straight quotes.
  • PHP does not interpret curly quotes as valid string delimiters.
  • As a result, PHP treated ‘DB_NAME’ as an undefined constant rather than a string literal.

Why This Happens in Real Systems

  • Copy‑pasting configuration snippets from blogs or PDFs often introduces smart quotes.
  • Text editors like Word, Notes, or some browsers automatically replace ' with or .
  • Configuration files require exact syntax, and even a single invalid character breaks execution.

Real-World Impact

  • Complete site failure: WordPress cannot load without valid DB credentials.
  • Misleading errors: Developers may think the database is broken when the real issue is syntax.
  • Debugging delays: Non‑technical users often spend hours troubleshooting the wrong component.

Example or Code (if necessary and relevant)

Below is the correct syntax using straight quotes:

define('DB_NAME', 'wordpress');

How Senior Engineers Fix It

  • Replace all curly quotes with straight ASCII quotes in wp-config.php.
  • Ensure the file is edited using a plain‑text editor (VS Code, Notepad++, Sublime).
  • Validate all other constants (DB_USER, DB_PASSWORD, etc.) for similar issues.
  • Enable PHP error display during local development to catch syntax issues early.
  • Use version control to detect accidental character changes.

Why Juniors Miss It

  • They assume all quotes are equivalent and don’t realize PHP requires strict syntax.
  • They often copy configuration snippets from formatted sources without checking characters.
  • They may not know how to interpret PHP fatal errors or trace them back to config files.
  • They expect WordPress to “just work” and overlook the importance of the wp-config.php file.

If you want, I can walk you through fixing your specific wp-config.php file line by line.

Leave a Comment