153 |
- |
1 |
<?php
|
|
|
2 |
ini_set("zlib.output_compression", "On");
|
|
|
3 |
ini_set("zlib.output_compression_level", 4);
|
|
|
4 |
ini_set("display_errors", 1);
|
|
|
5 |
ini_set("log_errors", 1);
|
|
|
6 |
ini_set("error_log", $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/logs/php_error.log");
|
|
|
7 |
ini_set("date.timezone", "America/New_York");
|
|
|
8 |
|
|
|
9 |
$dblink_in = mysqli_connect('localhost', 'vh3504_admin', 'uwe2592', 'vh3504_cheapmusic'); // connect live server
|
|
|
10 |
//$dblink_in = mysqli_connect('localhost', 'root', 'uwe2592', 'cheapmusic'); // connect live server
|
|
|
11 |
if (mysqli_connect_errno()) {
|
|
|
12 |
error_log("Failed to connect to MySQL: " . mysqli_connect_error());
|
|
|
13 |
exit;
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
$dblink_out = mysqli_init();
|
|
|
17 |
mysqli_ssl_set($dblink_out, $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/config/mysql-client-key.pem", $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/config/mysql-client-cert.pem", $_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/config/mysqld-ca-cert.pem", NULL, NULL);
|
|
|
18 |
mysqli_real_connect($dblink_out, '72.192.249.128', 'cheapmusic_php', 'uwe2592', 'cheapmusic_live', 3306, '', MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT); // connect copy server
|
|
|
19 |
//mysqli_real_connect($dblink_out, '10.192.25.240', 'root', 'uwe2592', 'cheapmusic_live', 3306, '', MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT); // connect copy server
|
|
|
20 |
if (mysqli_connect_errno()) {
|
|
|
21 |
error_log("Failed to connect to MySQL: " . mysqli_connect_error());
|
|
|
22 |
exit;
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
$tables = array('searches', 'transfers', 'barcodeChecks', 'geoLocation', 'searchPerformance', 'wishlist', 'users');
|
|
|
26 |
|
|
|
27 |
foreach($tables as $table) {
|
|
|
28 |
copyTable($table, $dblink_in, $dblink_out);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
mysqli_close($dblink_in);
|
|
|
32 |
mysqli_close($dblink_out);
|
|
|
33 |
|
|
|
34 |
function copyTable($table, $dblink_in, $dblink_out) {
|
|
|
35 |
$tableinfo = mysqli_fetch_array(mysqli_query($dblink_in, "SHOW CREATE TABLE $table") , MYSQLI_ASSOC); // get structure from table on server 1
|
|
|
36 |
mysqli_query($dblink_out, "DROP TABLE IF EXISTS $table");
|
|
|
37 |
mysqli_query($dblink_out, $tableinfo["Create Table"]); // use found structure to make table on server 2
|
|
|
38 |
$result = mysqli_query($dblink_in, "SELECT * FROM $table"); // select all content
|
|
|
39 |
$cnt = 0;
|
|
|
40 |
mysqli_begin_transaction($dblink_out);
|
|
|
41 |
|
|
|
42 |
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
43 |
$vals = array_values($row);
|
|
|
44 |
foreach ($vals as & $val) {
|
|
|
45 |
if ($val == null) {
|
|
|
46 |
$val = 'NULL';
|
|
|
47 |
}
|
|
|
48 |
else {
|
|
|
49 |
$val = "'" . mysqli_real_escape_string($dblink_out, $val) . "'";
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$sql = "INSERT INTO $table (" . implode(",", array_keys($row)) . ") VALUES (" . implode(",", $vals) . ")";
|
|
|
54 |
if (!mysqli_query($dblink_out, $sql)) {
|
|
|
55 |
error_log($sql);
|
|
|
56 |
error_log("Error description: " . mysqli_error($dblink_out));
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if (++$cnt > 100) {
|
|
|
60 |
mysqli_commit($dblink_out);
|
|
|
61 |
mysqli_begin_transaction($dblink_out);
|
|
|
62 |
$cnt = 0;
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
mysqli_commit($dblink_out);
|
|
|
66 |
}
|