选择从两个数据库连接的语句(在同一服务器中)

时间:2015-01-26 15:22:52

标签: php mysql

我一直在尝试使用相同的MySQL查询连接两个数据库,但我没有这样做。这是我的逻辑程序:

<?php
 // First connection
 $connection1 = mysqli_connect($dbhost1, $dbuser1, $dbpass1, $dbname1);
 // Second Connection
 $connection2 = mysqli_connect($dbhost2, $dbuser2, $dbpass2, $dbname2);

 $query = "SELECT DATABASE1 . TABLE1 . 'variable'
           FROM DATABASE1 . TABLE1 
           WHERE (DATABASE1 . TABLE1 . 'variable')
           IN (WHERE DATABASE2 . TABLE2 . 'variable'
               FROM DATABASE2 . TABLE2)";
 $result = mysqli_query($connection2, $query);

 while($row = mysqli_fetch_assoc($result)){
      echo "$row['variable']";
 }

?>

当我在SQL运行模块中运行MySQL查询时,我得到了预期的结果,但是当我尝试在php中运行它时它不起作用。 这是实际的代码:

<?php
// First connection this connects to the FIU database
 $connection1 = mysqli_connect($dbhost1, $dbuser1, $dbpass1, $dbname1);
 // Second Connection this connects to the FAU database
 $connectionINT = mysqli_connect($dbhost2, $dbuser2, $dbpass2, $dbname2);

 $queryCheaters = " SELECT FAU. FAU_01212015 . `stdName` FROM FAU . FAU_01212015 
 WHERE (FAU. FAU_01212015 . `remoteIP`) 
 IN (SELECT FIU . FIU_01232015 . `remoteIP` FROM FIU. FIU_01232015)";

 $check = mysqli_query($connectionINT, $queryCheaters);
?>

我已经单独运行了两个select语句,并且我在while循环中获得了变量,但我不确定我做错了什么。

提前致谢=)

0 个答案:

没有答案