Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need to know whether remote database connections are possible in every server? does every host provides the option for remote DB connection? and further this connection will be the second connection of the system. So there will be multiple database connections. How can I check if a host has enabled remote database connections?

share|improve this question
    
You're not going to get an answer for every server or hosting company. Do you want to remove those sentences? –  paulmorriss Mar 22 '12 at 14:40
add comment

2 Answers

Yes, it's possible, both mysql (mysql_connect) and mysqli allow you to specify a host for the connection. However, I suspect you can only check by trying: some hosting services might simply block outgoing connections using a firewall, which may be outside the web host machine and undetectable until you attempt to establish the connection.

If you're connecting to a server outside the same network as the server, it's worth considering turning on SSL.

This is not ideal mysql, since there is nothing to set the SSL options explicitly for your application. At best you can use mysql_options(&mysql->conn,MYSQL_READ_DEFAULT_GROUP, "client");, which will load the configuration from the [client] section of the global MySQL configuration file (on the web server). This can cause problems on a shared host.

If you're using mysqli instead, you should be able to use mysqli::ssl_set.

share|improve this answer
add comment

Most shared hosting accounts require you to give your self access to the mysql server. Usually you enter your IP address or a range to grant remote mysql access. Most other servers if you have root access you configure it yourself. You'll have to ask the hosting companies if remote mysql is allowed or if you have to grant your IP or another servers IP access which is connecting to the db

share|improve this answer
1  
Yep, most web hosts restrict access to their database servers to either localhost (if hosted on the web server) or hosts on the same network (if there are dedicated database servers). This is a security best practice as most web hosting database servers have no need to be accessed by any hosts outside the network. However, to access the database for development or administration purposes, I usually just use an SSH tunnel instead of adding my IP to the allowed hosts. This is typically more convenient on connections with dynamic IPs. –  Lèse majesté Mar 22 '12 at 9:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.