我目前正在使用 HostGator,但我的问题是我无法使用我的 localhost
PHP 文件连接到我的在线数据库(即 HostGator)。我希望如果我有互联网连接,我将连接到我的在线数据库,但如果没有,我将连接到我的离线 localhost
数据库。这是我的代码:
$checknet = @fsockopen("www.mysite.com", 80);
if(isset($checknet)) {
mysql_connect('mysite.com OR ip of mysite','username','password');
mysql_select_db('db');
} else {
mysql_connect('localhost','root','');
mysql_select_db('db');
}
另外,我已经将我的IP地址添加到数据库的访问白名单中了。但是,从远程系统访问数据库仍然不起作用。
最佳答案
您必须将您的公共(public) IP 地址列入白名单。
a) Google "what is my ip"
b) Follow the tutorial on this link.
关于php - Hostgator远程访问本地php文件中的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35694429/