InMotion Hosting Support Center

How do I connect to a MySQL Database with PHP?

Category: Databases

2013-09-11 9:51 am EST

Hits: 1,655
I've used PHP with MYSQL previously on inMotion with no troubles. However, with a new account I cannot seem to run a simple PHP script that outputs some sample MySQL data. I am included to think there is something wrong with my account because I followed your example on this page ( ) exactly but it fails on line #16 when setting the connection. I can send you my code if you like. The url where I am simply trying to set up the simple PHP page is here:

Phil Threadgould
Account Name = XXXXXXX

You must login before you can ask a follow up question.

You must login before you can submit an answer.

Ok, I figured it out. Although I had setup the database and setup the user. Assigning the user permissions to SELECT, DELETE, etc. on the database had not been granted. This is an extra step that is not very clear in the documentation. If you use the wizard, then it will setup everything you need.
5 Points
2013-09-11 09:58 am EST
Hello thread7, and thanks for the feedback!

I went ahead and updated the connecting to a database using PHP article. So it's a bit more clear now that you must also assign a database user to a database before your PHP script can connect.

Please let us know if you had any other feedback at all, and thanks again!

- Jacob
9,968 Points
2013-09-12 04:39 pm EST



30,622 Points
2013-09-11 11:17 am EST
Hello thread7,

Thank you for letting us know you were able to get it working. For anyone else who may find this post, here is a link to our guide on How to create a MySQL Database.

After it is created, you can create and attach a user to the database in cPanel.

Then, you will be able to connect to it using PHP.

If you have any further questions, feel free to post them below.
Thank you,


You must login before you can post a comment about this answer.

Like this Question?

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!