-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.php
47 lines (42 loc) · 1.76 KB
/
convert.php
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
<?php
require_once('checkConn.php');
class ConvertStorageEngine
{
function convertAllTablesEngine($from, $to)
{
if (isset($_SESSION['dbName'])) {
$db = $_SESSION['dbName'];
$user = $_SESSION['dbUser'];
$password = $_SESSION['dbPassword'];
$checkCon = new CheckConn();
$pdo = $checkCon->checkConnection($db, $user, $password);
$alertMessage = '';
$arr = [];
$results = $pdo->query("show tables;");
$i = 0;
while ($row = $results->fetch()) {
$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' .$db]}'";
$thisTable = $pdo->query($sql)->fetch();
if ($thisTable['Engine'] === $from) {
$sql = "alter table " . $row['Tables_in_' . $db] . " ENGINE =" . $to . ";";
$alertMessage = "<tr class='bg-success'><td>$i</td><td>{$row['Tables_in_' .$db]}</td><td> Converted from {$thisTable['Engine']} to $to.</td></tr>";
$arr[$i] = $alertMessage;
$pdo->query($sql);
} else {
$alertMessage = "<tr class='bg-warning'><td>$i</td><td>" . $row['Tables_in_' . $db] . '</td><td> Engine Type is ' . $thisTable['Engine'] . ' nothing changed!</td></tr>';
$arr[$i] = $alertMessage;
}
$i++;
}
}
echo json_encode($arr);
}
}
if (class_exists('ConvertStorageEngine')) {
if (isset($_SESSION['login']) && $_SESSION['login'] === true && isset($_POST['from'])) {
$from = $_POST['from'];
$to = $_POST['to'];
$convert = new ConvertStorageEngine();
$convert->convertAllTablesEngine($from, $to);
}
}