简体   繁体   English

如何使用php通过本地服务器连接托管服务器数据库?

[英]how to connect hosted server database through local server using 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";
}
?> 

when i run this file in local server (xammp server) it could n't be connect i get 当我在本地服务器(xammp服务器)中运行此文件时,无法连接我得到

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

i get "not connect" response 我得到“不连接”响应

can any one guide me 谁能指导我

Thanks for advance. 感谢前进。

There a three things you need to connect to a remote database: 连接到远程数据库需要完成三件事:

  • port 3306 open on the firewalls. 在防火墙上打开端口3306。 Firewalls in server and client must open port 3306! 服务器和客户端中的防火墙必须打开端口3306!
  • in my.cnf bind-address = 0.0.0.0 to let mysql bind to all interfaces 在my.cnf bind-address = 0.0.0.0中让mysql绑定到所有接口
  • sufficient privileges in the database to allow remote connections 数据库中足够的特权以允许远程连接

Virtual all hosting companies close port 3306 on the firewall, and do not allow direct remote access. 虚拟所有托管公司都关闭防火墙上的端口3306,并且不允许直接远程访问。 And even if they do, you won't get privileges to connect to a database. 即使他们这样做,您也不会获得连接数据库的特权。

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. 仅当远程数据库位于您的LAN中或使用具有root访问权限的VPS时,您才可以配置内容以建立远程连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将托管的php网站连接到本地服务器上的SQL Server数据库 - how to connect my hosted php website to SQL Server Database on my local server 如何通过PHP连接SQL Server数据库? - How to connect to SQL Server database through PHP? 如何使用PHP从本地wamp服务器连接在线mysql数据库服务器? - how to connect online mysql database server from local wamp server using php? 我想通过托管在远程服务器上的PHP脚本访问本地mysql数据库 - I would like to access a local mysql database through my php script hosted on a remote server 本地服务器无法使用 PHP 连接到远程 postgresql 数据库,但本地终端可以连接 - local server can't connect to remote postgresql database using PHP, but local terminal can connect 使用php连接到本地计算机上的生产服务器 - Using php connect to production server in local machine 如何通过代理使用curl和php连接到远程服务器? - How to connect to the remote server using curl and php through proxy? 如何从godaddy中托管的远程服务器访问本地MySql数据库 - How to Access a local MySql database from a remote server hosted in godaddy 如何使用 php 将 opencart 应用程序连接到 ms sql server 数据库? - How to connect an opencart application to an ms sql server database using php? 无法连接到PHP中的数据库(使用WAMP服务器) - Unable to connect to database in php (using wamp server)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM