PHP can’t connect to MySQL Database (timeout)

I started experimenting with PHP and now I wanted to connect with a MySQL Database and have tried every way you can find on the Internet (mysqli and pdo), but every time the connection times out.
What i also need to say is that the Database is running on a external server and not on localhost

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I guess you’re running your php code on your own machine and MySQL on a hosting service.

Many hosting services simply don’t allow connections to MySQl from outside their private networks. Because cybercreeps. If that’s your situation you need a different hosting service.

Others require some special configuration setting. It sometimes appears on cpanel as something like “Remote database access”. Ask their tech support. And make sure you use the correct hostname when connecting.

If you are new to this stuff you may get the best setup for your learning by installing MySql locally. Trying to learn both database programming and the necessary network engineering for a remote connection at the same time? Huuuge pain in the xxs neck. Can you install WAMP? Amps?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x