简体   繁体   中英

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

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM