4

別のサーバーからmysqlデータベースサーバーに接続しようとしています。以下は、両方のサーバーの構成です。

サーバー1:phpおよびapacheサービスを使用してxamppをインストールしましたが、次のIPがあります172.x1.x1.x1

サーバー2:mysqlをインストールしましたが、次のIP172.x1.x1.x2があります。

以下は、データベースへの接続に使用している接続スクリプトです

<?php
    //Database connection constants
    define("DATABASE_HOST", "172.x1.x1.x2");
    define("DATABASE_USERNAME", "root");
    define("DATABASE_PASSWORD", "");
    define("DATABASE_NAME", "management");
?>

上記のスクリプトはapp_config.phpというファイルにあり、サーバー1にあります。次のスクリプトはconnect.phpというファイルにあり、サーバー1にもあります。

<?php
require 'app_config.php';
$connect_error = 'Sorry we\'experiencing connection problems.';
$table_error = 'Table not found';
mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD)
or die($connect_error);

mysql_select_db(DATABASE_NAME)またはdie($ table_error); ?>接続しようとすると、次のエラーが発生します

警告:mysql_connect()[function.mysql-connect]:ホスト'hr1.saqa.co.za'は、C:\ xampp \ htdocs \ scripts \ functions \ database \connect.phponにあるこのMySQLサーバーに接続できません。 4行目

致命的なエラー:5行目のC:\ xampp \ htdocs \ scripts \ features \ database \ connect.phpにある未定義の関数handle_error()を呼び出します

あなたが私たちを助けることができればそれは恐ろしいでしょう。

4

2 に答える 2

3

Since your database server is different from your php/apache server you need to specify the hostname as 172.x1.x1.x2 in mysql-php connection string.

Also make sure that mysql user root have remote connection permission. Other wise mysql-server will not allow your root user to login remotely. i.e. from your server1.

You can make sure that from mysql.user table.

mysql> select Host,User from user where User = "root";
+------------+------+
| Host       | User |
+------------+------+
| 127.0.0.1  | root |
| ::1        | root |
| localhost  | root |
| sgeorge-mn | root |
| %          | root |
+------------+------+
4 rows in set (0.01 sec)

% means any host.

To create a user with remote connection permission, use following mysql query:

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'your_password';
于 2013-01-21T12:26:35.323 に答える
2

1)Make sure firewall Allow MySQL.

2)Make sure MySQL remote connection permission Allowed .

于 2013-01-21T12:33:23.177 に答える