问题
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