I am trying to connect to MySQL database at on host (DBhost) from another host (PROGRAMhost).

While I try to connect to the database at DBhost from DBhost itself the next is working fine for me:
mysql_connect("localhost","qdbname","dbpassword")

Now I am trying to find out what to use instead of localhost? I tried to replace localhost with host's url:port (I tried number of ports) but this is not working (even when I am connecting from DBhost itself). How can I find out what is the proper value to use instead of localhost?

Recommended Answers

All 3 Replies

sounds like your hostname is not being resolved through the DNS. Have you tried using an IP address to see if thats the problem? If you can't connect using an ip address then something (firewall?) is blocking the connection.

If you're on windows machines you can edit hour hosts file and get the name resolution there. \windows\system32\drivers\etc\hosts and just map ip address to hostname with something like 192.168.1.210 database_server. BTW, this is where the name localhost is defined on your system.

Member Avatar for rajarajan2017

Give just your IP address of the system you connecting.

mysql_connect("192.0.22.2","qdbname","dbpassword")

In that system phpAdmin should configured

Hello,

You also need to add a user to the mysql users table that connects from the remote IP. (i.e. dbuser@192.169.1.2 ) to tell mysql it is ok to accept connections from that host as that user to the specified database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.