If the DBMS and Web Server are on the same machine, connect using sockets or localhost loopback.
If that's not it, make sure the DB server accepts incoming connections on whatever port your DBMS wants them and that the user trying to connect exists and is allowed to do so from whatever IP your web server uses.