连接到10个mysql数据库,只运行与所有数据一起运行

时间:2017-07-20 13:09:31

标签: php mysql

我尝试连接10个相同的mysql数据库,以一条很好的直线打印它们。

这里有没有人能给我一个如何运作的例子?

$servername = "localhost";
$username1 = "***";
$password = "***";

$v1 = "wp282";
$v2 = "wp111";
$v3 = "wp72";
$v4 = "wp193";
$v5 = "wp555";
$v6 = "wp366";
$v7 = "wp74";
$v8 = "wp721";
$v9 = "wp924";
$v10 = "wp253";

$conn =   mysqli_connect($servername, $username1, $password, $v1 "v2,v3,v4,v5,v6,v7,v8,v9,v10");
$query100 = mysqli_query($conn, "SELECT * FROM `wpd2_posts` where post_status='wc-processing' or post_status='wc-completed' or post_status='wc-failed' order by post_date DESC LIMIT $sidenr2,50") or die(mysqli_error($conn));   

while($row = mysqli_fetch_array($query100))         
{
   echo $row['ID'];
}

1 个答案:

答案 0 :(得分:-1)

这似乎是一个奇怪的请求,但当然可以做到。

$servername = "localhost";
$username1 = "***";
$password = "***";

$databases = array("wp282","wp111","wp72","wp193","wp555",
                    "wp366","wp74","wp721","wp924","wp253");

foreach ( $databases as $database ) {
    $con = new mysqli($servername, $username1, $password, $database);

    $result = $con->query($con, "SELECT * 
                                    FROM `wpd2_posts` 
                                    where post_status='wc-processing' 
                                    or post_status='wc-completed' 
                                    or post_status='wc-failed' 
                                    order by post_date DESC 
                                    LIMIT $sidenr2,50") 
                    or die($con->error);   

    while($row = $result->fetch_assoc()) {
        echo $row['ID'] . ' ';
    }
    $con->close();
}
  

我不知道$sidenr2来自哪里