i have found the solution.
the user didn’t have the rights to communicate with the server.so i created a user that has all the server privileges and added the database name and the other details on the wp-config.php file then uploaded it on the site.
once i typed in the domain it took me straight to the LOGIN page .
i finally got the solution after 4 hours
i have checked my database details. the password is correct and so is the username.
the database name is also correct i checked letter by letter but the error still appears i have cleared my cache but the error still appears.
i do not know what to do now