-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.php
More file actions
51 lines (40 loc) · 1.7 KB
/
migrate.php
File metadata and controls
51 lines (40 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require 'debug.php';
require 'model.php';
echo '<head><style>body{background: #111;color: #fdfdfd;font-size: 1.5rem;font-family: Roboto, sans-serif;}</style></head>';
$tables = $_SESSION['migrate_tables'];
for ($m = 0; $m < sizeof($tables); $m++) {
${'cols_'.$tables[$m]} = [];
// To avoid tables with similar names
$total_cols_rows = $db->countRows("DESCRIBE $tables[$m];");
for ($n = 0; $n < $total_cols_rows; $n++) {
${'cols_'.$tables[$m]}[$n] = $db->getColumn("INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'".$tables[$m]."' LIMIT 1 OFFSET $n;", 'COLUMN_NAME');
}
// remove the 'id' column
array_shift(${'cols_'.$tables[$m]});
}
// Table Loop
for ($table_loop = 0; $table_loop < sizeof($tables); $table_loop++) {
$cols_array = ${'cols_'.$tables[$table_loop]};
$cols_array_num = count($cols_array);
$total_rows = $db->countTableRows($tables[$table_loop]);
// Row Loop
for ($row_loop = 0; $row_loop < $total_rows; $row_loop++) {
echo "INSERT INTO $tables[$table_loop] (";
// Column Loop
// For column names
for ($cols_loop = 0; $cols_loop < $cols_array_num; $cols_loop++) {
echo $cols_loop == ($cols_array_num - 1) ? $cols_array[$cols_loop] : $cols_array[$cols_loop].',';
}
echo ') VALUES(';
$offset = $row_loop;
// For column values
for ($l = 0; $l < $cols_array_num; $l++) {
$cols_value = '\''.$db->getColumn(''.$tables[$table_loop]." LIMIT 1 OFFSET $offset", $cols_array[$l]).'\'';
echo $l == ($cols_array_num - 1) ? $cols_value : $cols_value.',';
}
echo ');';
echo '<br><br>';
}//end for
echo '<br><br>';
}//end for