如何使用php通过本地服务器连接托管服务器数据库? [英] how to connect hosted server database through local server using php?

查看:73
本文介绍了如何使用php通过本地服务器连接托管服务器数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过本地服务器连接托管服务器数据库,这是我的代码

i want to connect hosted server database through local server here is my code

<?php
$con=mysql_connect("myserverDbHostname","mydatabaseUsername","Password");
if($con)
{
echo "connect";
mysql_select_db("DatabaseName");
else
{
echo "not connect";
}
?> 

当我在本地服务器(xammp 服务器)上运行这个文件时,它无法连接我得到

when i run this file in local server (xammp server) it could n't be connect i get

Warning: mysql_connect() [function.mysql-connect]: Can't connect to
MySQL server on

我收到未连接"响应

谁能指导我

感谢提前.

推荐答案

连接远程数据库需要三件事:

There a three things you need to connect to a remote database:

  • 端口 3306 在防火墙上打开.服务器和客户端的防火墙必须打开 3306 端口!
  • 在my.cnf中bind-address = 0.0.0.0让mysql绑定所有接口
  • 在数据库中有足够的权限以允许远程连接

几乎所有托管公司都关闭了防火墙上的 3306 端口,并且不允许直接远程访问.即使他们这样做,您也不会获得连接到数据库的权限.

Virtual all hosting companies close port 3306 on the firewall, and do not allow direct remote access. And even if they do, you won't get privileges to connect to a database.

仅当远程数据库在您的 LAN 中,或者您正在使用具有 root 访问权限的 VPS 时,您才能进行配置以建立远程连接.

Only if the remote database is in your LAN, or you are using a VPS with root access you can configure things to make a remote connection.

这篇关于如何使用php通过本地服务器连接托管服务器数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆