Error establishing a database connection on wordpress
If your are not using default port 3306 for MySql, do give the host name with port number.
define('WP_HOME','http://www.mysite.com');define('WP_SITEURL','http://www.mysite.come');define('DB_NAME', 'mydbname');/** MySQL database username */define('DB_USER', 'dbusername');/** MySQL database password */define('DB_PASSWORD', 'dbpassword');/** MySQL hostname */define('DB_HOST', 'localhost:3307'); //If you are not using default port number, do give post number along with localhost.
This would work
Try changing your DB_HOST to localhost
** MySQL hostname */define('DB_HOST', 'localhost');
Furthermore, have you set up the database and filled in the username, password & database in your config?
If you get it 'sometimes' then it means the PHP Scrpt wasn't able to connect to the database. One of the various reasons could be database server down for a while.