Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14625 reviews 1734 hosting providers

Questions & Answers

PHP can't access MYSQL database

Mar 21, 2012 by GeekNew
Hello everyone

My PHP program tells me it can't access the MYSQL database because of incorrect username/password. I've checked the configuration settings in my script and everything in there looks normal. can anyone tell me what to do?

1 Answer

0 votes
Mar 21, 2012 by mike231
Hi there,

When you create your MySQL database, first you create a database by giving it a name. Then you create a user by entering a username and password. For best results keep your database name, database username, and database password at no fewer than 6 and no more than 7 letters or numbers. Then you must be sure to add the user to the database.
In your script, your database name and your database username must be prefaced by your hosting account username_. Your password, however, stands alone. For example: If your hosting account username is "joedoe1", your database name is "testdb", your database username is "dbuser", and your database password is "passwd", here is how you need to put them in your script:
database server should usually be localhost
database name should be written as joedoe1_testdb
database username should be written as joedoe1_dbuser
database password should be written simply as passwd

hope this helps