我的主机上有两个网站,每个网站都链接到自己的数据库。两者都在 WordPress 上。我正在尝试与两个数据库建立两个单独的连接,并从一个数据库下载信息并将信息放入另一个数据库中。这是我得到的:
<?php
$servername = "localhost";
$database = "xxxxxxxxxx";
$username = "xxxxxxxxxxxx";
$password = "xxxxxxxxxxxx";
$servername2 = "localhost";
$database2 = "xxxxxxxxxxxxxx";
$username2 = "xxxxxxxxxxxxx";
$password2 = "xxxxxxxxxxxxx";
$conn = mysqli_connect($servername, $username, $password, $database);
$conn2 = mysqli_connect($servername2, $username2, $password2, $database2);
$sql = "SELECT * FROM wp_posts";
$counter = 600;
$iterator = 1;
if($result = $conn->query($sql)){
foreach($result as $row){
$stringArr[] = "(" . $counter . ", '" . $row['post_author'] . "', '" . $row['post_date'] . "', '" . $row['post_date_gmt'] . "',
'" . $row['post_content'] . "', '" . $row['post_title'] . "', '" . $row['post_excerpt'] . "',
'" . $row['post_status'] . "', '" . $row['comment_status'] . "', '" . $row['ping_status'] . "',
'" . $row['post_password'] . "', '" . $row['post_name'] . "', '" . $row['to_ping'] . "',
'" . $row['pinged'] . "', '" . $row['post_modified'] . "', '" . $row['post_modified_gmt'] . "',
'" . $row['post_content_filtered'] . "', '" . $row['post_content_filtered'] . "', " . $row['post_parent'] . ",
'" . $row['guid'] . "', " . $row['menu_order'] . ", '" . $row['post_type'] . "', '" . $row['post_mime_type'] . "',
" . $row['comment_count'] . ")";
/*
if($iterator%50 == 0) {
print_r($stringArr);
exit;
}*/
$iterator++;
$counter++;
/*
print_r($string);
$sql2 = "INSERT INTO serjam_wp1.wp_post VALUES (" . $string . ")";
if ($conn2->query($sql2) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
*/
// print_r($string);
}
}
$sql2 = "INSERT INTO serjam_wp1.wp_post VALUES (" . implode(",", $stringArr) . ")";
if ($conn2->query($sql2) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
如果我只是在浏览器中显示数据库的内容(信息已经存在),那么我就可以得到一切。
也就是说,如果没有 INSERT 代码,则该脚本将起作用。但如果是,那么 SELECT 将停止工作。我从信息所在的站点运行脚本。

如果您不想破坏基础,请不要这样做。为了将职位(不仅是)转移到 VI,有一个标准的导出-导入工具。