1. Home
  2. Computing & Technology
  3. PHP / MySQL

How Can I Fix A Database Connection Error?

By , About.com Guide

Question: How Can I Fix A Database Connection Error?

Although this could indicate a bigger problem, usually a connection error is a result of a few simple things described below.

Answer:

  1. You could connect fine yesterday, and haven't changed any code in your script. Suddenly today it's not working!!

    This is probably a problem with your hosting. Your hosting provider may have the databases offline for maintenance or because of an error. Contact them to see when they are expected back up.

    If your database is on a different URL than the PHP file you are connecting to it from, it could be that you let your domain name expire. Sounds silly, but it happens a lot.

  2. I am trying to connect to localhost and it's not working!

    Localhost doesn't always work, so you need to point directly to your database. Often it's something like mysql.yourname.com or mysql.hostingcompanyname.com. If you ask your hosting company they can point you in the right direction.

  3. I know my host name is correct, and I still can't get it to work!

    Double check your username and password...then triple check them. This is one people often overlook, or check so quickly they don't even notice their mistake. Not only do you need to check that they are correct, you should make sure they have the correct permissions for what your script requires. For example, a read only user can't add data to the database... they would also need write privileges.

More PHP / MySQL Q&A
Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Troubleshooting
  5. MySQL Connect Error - Database Connect Error - Error Connecting to Database

©2009 About.com, a part of The New York Times Company.

All rights reserved.