how to connect hosted server database through local server using php?

僤鯓⒐⒋嵵緔 提交于 2019-12-13 06:47:09

问题


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

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.


回答1:


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

  • port 3306 open on the firewalls. Firewalls in server and client must open port 3306!
  • in my.cnf bind-address = 0.0.0.0 to let mysql bind to all interfaces
  • 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. 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.



来源:https://stackoverflow.com/questions/12367007/how-to-connect-hosted-server-database-through-local-server-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!