Php 使用数据库连接数据所在的不同服务器访问mysql

Php 使用数据库连接数据所在的不同服务器访问mysql,php,mysql,Php,Mysql,我试图包含一个包含我所有数据库连接信息(主机名密码用户名)的文件 这就是我到目前为止所做的: include ('http://site.com/config35sdf322e54353452d/wp2154654315634652132513546541564.php'); mysql_connect($hostname,$username,$password); @mysql_select_db($dbname) or die( "Unable to select database");

我试图包含一个包含我所有数据库连接信息(主机名密码用户名)的文件

这就是我到目前为止所做的:

include ('http://site.com/config35sdf322e54353452d/wp2154654315634652132513546541564.php');

mysql_connect($hostname,$username,$password);
@mysql_select_db($dbname) or die( "Unable to select database");

include ('../refference.php');
$select = mysql_query("SELECT my_field FROM $usertable WHERE ".
"GDI_Username = '$sponsor_GDI_id' AND Unique_id = '$sponsor_refference'");


while($check = mysql_fetch_array($select)) {
    $sponsor_email = $check["email"];
    $sponsor = $check["GDI_Username"];
    $sponsor_first_nme = $check["First_Name"];
    $sponsor_second_nme = $check["Last_name"];
    $sponsor_domain = $check["GDI_Domain"];
    $unq_id = $check["Unique_id"];
 } 

$sponsor_name = "$sponsor_first_nme $sponsor_second_nme";

echo "$sponsor $hostname" ?>
我收到一个错误,说它无法选择数据库(“无法选择数据库”)

经过一些调查(代码末尾有echo语句),它似乎出现了问题,包括不同服务器上的.php文件错误代码:
include('s)http://site.com/config35sdf322e54353452d/wp2154654315634652132513546541564.php');

有什么线索吗


谢谢

您不能包含来自不同域的php文件

或者

 mysql_connect(); 

失败,但您没有错误处理程序

您可以通过在PHP.ini文件中启用
allow\u url\u include
功能,从远程服务器包含PHP文件

或者,您可以在运行时通过将其添加到脚本顶部来启用它

ini\u集('allow\u url\u include',1)

然而,这可能会导致安全问题(例如,它允许攻击者包含远程文件,如shell)

$hostname应该是您的远程主机,如www.remotehost.com192.168.0.100

此外,必须将远程主机配置为远程访问

正如genesis所说,“您不能包含来自不同域的php文件”

mysql_connect($hostname,$username,$password);