Working through the causes.
THE ERROR
Error establishing a database connection, or access denied, or unknown database.
THE FOUR VALUES TO CHECK
Database name, including the cPanel prefix Username, including the prefix Password Host, which should be localhost
Compare the configuration file against cPanel > MySQL Databases.
THE MOST COMMON CAUSE
The prefix missing from the name or the username. Particularly after a migration, where the old credentials came with the files.
THE SECOND MOST COMMON
The user exists but is not assigned to the database, or lacks privileges.
THE RELIABLE FIX
Create a fresh database user, assign it with all privileges, and update the configuration.
Faster than diagnosing which of the four values is wrong.
IF ALL FOUR ARE DEFINITELY CORRECT
The database server may be unreachable. Open a ticket.
Check whether other sites on the account also fail. If they do, it is not your configuration.
AFTER A CPANEL PASSWORD CHANGE
Associated database passwords are sometimes reset. If the site failed immediately afterwards, this is why.