Ajay516
Ajay516

Reputation: 43

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.

Upvotes: 0

Views: 2272

Answers (1)

JvdBerg
JvdBerg

Reputation: 21866

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.

Upvotes: 0

Related Questions