2010-11-02 47 views

回答

1

您需要:配置

  1. 數據庫服務器應用程序,允許從外部主機

  2. 服務器端的網絡配置調整,以允許來自外部主機連接的連接(防火牆,NAT,...)

  3. 數據庫用戶,其被授權訪問數據庫時要使用

  4. PHP應用程序,它在適當的用戶

細節取決於什麼數據庫服務器上您使用連接到您的數據庫服務器。

1
$link = mysql_connect($host, $username, $password); 

順便說一句,沒有什麼安全的。

1

我使用類似這樣的東西,但它遠非安全。我把它保存在一個單獨的「connection.php」中,這些文件只需要一次。

$db_host = 'INSERT IP HERE'; 
$db_user = 'User'; 
//My sql password for testing purposes 
$db_pass = 'PASSWORD'; 
//name of the database 
$db_name = 'dbname'; 

//connection 
$conn = new mysqli($db_host, $db_user, $db_pass ,$db_name); 

if (mysqli_connect_errno()) 
{ 
    printf("Error connecting to DB, Errorcode: %s\n", mysqli_connect_error()); 
    exit; 
} 
1

使用MERCH會員的答案 - 上面的php代碼。 您需要授予權限並在要從中檢索數據庫數據的服務器上創建用戶。

連接到MySQL: 在鍋殼式(如果你是根類型根或任何用戶名): 的mysql -u根-p

輸入密碼,

當您登錄:

create user [email protected] identified by 'password'; 
grant all privileges on *.* to [email protected] with grant option; 

現在你可以使用上面的PHP代碼連接到遠程服務器數據庫(IP你只是用來創建mysql用戶的客戶端-IP)

當你創建MySQL的PHP​​變量連接 - 主機用mysql端口的變量,如果只是IP連接不是你的客戶端-IP:3306

好運

相關問題