使用PHP连接到远程MySQL数据库的网页

I manage to use a PHP script to connect my web page to a remote MySQL Server, but this requires port 3306 on the remote server to be open, which is a security concern. I need this functionality for my web site visitors, which of course eliminates the idea of allowing some predefined IP addresses.

So, how can I go about it, maybe with something like SSH Tunnelling?

Thanks Alex

Personally, I've found that the best way for me that provides a good balance of security and performance, is to have port 3306 open but set a firewall rule restricting access to my web server's IP address.

You can use IP Tables to filter network traffic with a rule like this:

iptables -I INPUT -p tcp -s [WEBSERVER IP ADDRESS] --dport 3306 -j ACCEPT

You could combine that with connecting to the mysql server securely, as well if you want the data encrypted during its trip from the MySQL server to the web server. See this Stackoverflow article: Securing remote mysql connection