将远程服务器 mysql 数据库连接到本地主机 [英] Connecting remote server mysql database to localhost

查看:78
本文介绍了将远程服务器 mysql 数据库连接到本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的 localhost PHP 文件连接到我的远程服务器 MYSQL 数据库?

How can I connect my localhost PHP files to my remote server MYSQL database?

例如:如果我们下载 WordPress,并且它给了我们一个登录选项,这样我们的登录凭据就会与 WordPress 一起保存,但我们的 localhost 文件仍然连接到那个数据库.我该怎么做?

For example: if we download WordPress, and it gives us an option to login, so that our login credentials are saved with WordPress but still our localhost files connects to that database. How do I do that?

谢谢.

推荐答案

如果你想让你的 PHP 代码连接到远程 MySQL 数据库,你只需要在调用连接到 MySQL 的函数时指定远程主机.

If you want your PHP code to connect to a remote MySQL database, you just have to specify that remote host when calling the function that connects to MySQL.

>

例如调用mysql_connect()时,不要指定localhost 作为第一个参数——但你真正的远程主机.
mysqli::__construct()PDO,当然.

For example, when calling mysql_connect(), don't specify localhost as first parameter -- but your real remote host.
Same with mysqli::__construct() or PDO, of course.


一些注意事项:


A couple of notes :

  • 您的远程主机必须接受与 MySQL 的连接(想想防火墙)
  • 您的远程 MySQL 数据库服务器必须接受来自非本地主机的连接
  • 向/从远处的服务器发送查询和获取结果将比在 localhost 上执行要慢得多!

这篇关于将远程服务器 mysql 数据库连接到本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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