1

It's a simple thing really. But I can't solve it so I'm hoping someone will quickly give me the answer.

I got two separate servers. The MySQL database is hosted on server #1, and the PHP files on that server are running the website by making queries. Now I'd like to have the same content on website #2, by accessing the same database remotely and running the DB queries.

I have given the remote IP access to the DB on server #1. I have copied the same PHP file (which is making the queries on server #1) to server #2 and changed 'localhost' to IP address of that server. The username and the password remained the same.

When I run that PHP file I get a message "Database NOT found".

This is the PHP code which accesses the database on server #1, the same server where the database is:

$user_name = "database_xxx";
$password = "xxx";
$database = "database_name";
$server = "localhost";

And this is the second case, the PHP file on server #2 which is supposed to access the same database:

$user_name = "database_xxx";
$password = "xxx";
$database = "database_name";
$server = "xx.xxx.xxx.xxx"; //IP address of server #1
4

2 に答える 2

2

ファイアウォールをチェックし、リモートホストがDBを使用してマシンに接続していることを確認したため、それらはアウトになっていると言います。その後、最も簡単に確認できるのは権限です。アクセス許可はuser@host&に付与されていることに注意してくださいuser@localhost。その後、データベース構成を確認します。

于 2012-05-24T17:30:36.847 に答える
0

Cpanelを使用している場合に実際に行うべきことは、[データベース]の下の[リモートMySql]に移動することです...[入力]フィールドで、許可された接続を要求します。サーバー#2のドメイン名を入力し、質問で指定したのと同じ構成を入力しますが、今回は、サーバー#1のIPアドレスをサーバー#2のPhp接続コードに入力する代わりに、サーバー#1のドメイン名を入力します。例えば

$user_name = "database_xxx";
$password = "xxx";
$database = "database_name";
$server = "server#1.com"; //Domain name address of server #1
于 2012-05-24T18:48:49.370 に答える