Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jiri Stepanek
Jiri Stepanek
10,740 Points

"Connection refused" when I'm trying to connect to the database

Hello, I'm trying to connect to the database, but from different domain. I'm doing it like this –>

mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD);

It returns error "Connection refused", I tried almost everything, do you have any ideas?

3 Answers

When you say "but from different domain", can you give more info? We don't need your username and password, but domain/host info would be good :)

More importantly, mysql_connect has been deprecated for quite some time and is insecure, see this. I would recommend creating a connection via PDO MySQL instead.

Jiri Stepanek
Jiri Stepanek
10,740 Points

Hi Tom, I'm working in a team and I have been told that I can't use PDO. And the domain I'm trying to connect to is "db.comidamed.cz". I hope that you will not try to hack it or something :D

You need not worry about that!

Well that seems totally awful, but nevermind :p

You might be missing a port number e.g. localhost:3306. I would also try switching out the domain for an ip address and see how far that gets you.

Also the obvious - make sure your username and password are correct!

If all the credentials and ports etc are right, you'll probably need to start looking at the database, making sure it's accepting foreign connections okay.