forked from sbulen/sjrbTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMF_InnoDB_Converter.php
123 lines (101 loc) · 3.02 KB
/
SMF_InnoDB_Converter.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
//
// A utility to convert all tables that match your smf db prefix to InnoDB
// *** SMF 2.0 & 2.1 ***
// *** MySQL v5.5+ only ***
//
// Usage guidelines:
// (1) Use at your own risk.
// (2) ALWAYS run in your test environment first.
// (3) ALWAYS backup your system first - expect the unexpected.
// (4) Copy this file to your base SMF directory - (the one with Settings.php in it).
// (5) Execute it from your browser.
// (6) Delete it when you're done.
// by sbulen
//
//*** Main program
doStartup();
doSettingsFile();
doInnoDB();
doWrapUp();
return;
//*** Startup
function doStartup() {
// Without this header, flushes don't work...
header( 'Content-type: text/html; charset=utf-8' );
echo("<br>**********************<br>");
echo("*** InnoDB Converter ***<br>");
echo("**********************<br><br>");
define('SMF', 1);
// Yes, both flushes necessary
@ob_flush();
@flush();
return;
}
//*** Settings File
function doSettingsFile() {
global $db_type, $db_connection, $db_prefix, $db_name, $smcFunc;
$smcFunc = array();
$dumpvars = array('mbname', 'boardurl', 'db_server', 'db_name', 'db_prefix', 'language', 'db_type', 'db_character_set');
// Load the settings...
require_once(dirname(__FILE__) . '/Settings.php');
$settings[0] = array('Settings.php Var','Value');
foreach($dumpvars as $setting)
$settings[] = array('$' . $setting, (isset(${$setting}) ? ${$setting} : '<strong>NOT SET</strong>'));
dumpTable($settings);
// Get the database going!
if (empty($db_type) || $db_type == 'mysqli')
$db_type = 'mysql';
// Make the connection...
$db_connection = mysqli_connect($db_server, $db_user, $db_passwd, $db_name);
return;
}
//*** do the conversion
function doInnoDB() {
global $db_connection, $db_prefix;
// Do them tables
$sql = "SHOW TABLES LIKE '" . $db_prefix . "%'";
$result = mysqli_query($db_connection, $sql);
while($table = mysqli_fetch_assoc($result)) {
foreach ($table as $value) {
$result2 = mysqli_query($db_connection, "SHOW CREATE TABLE " . $value);
$createstuff = mysqli_fetch_row($result2);
if (!strpos($createstuff[1], 'ENGINE=InnoDB')) {
echo(" Working on table: " . $value . "... ");
@ob_flush();
@flush();
mysqli_query($db_connection, "ALTER TABLE $value ENGINE=InnoDB;");
echo("Result: " . mysqli_errno($db_connection) . " " . mysqli_error($db_connection) . "<br>");
@ob_flush();
@flush();
}
else {
echo(" Bypassing table - Already InnoDB: " . $value . "<br>");
@ob_flush();
@flush();
}
}
}
}
//*** Wrap Up
function doWrapUp() {
echo "<br>Your tables have been converted to InnoDB!<br><br>";
// Yes, both flushes necessary
@ob_flush();
@flush();
return;
}
//*** Dump Table
// Takes a simple 2 dimensional array & dumps it in table format
function dumpTable($passedArray) {
echo '<br><table border="1" cellpadding="3" frame="border" rules="all">';
foreach($passedArray as $row) {
echo '<tr><td>';
echo implode('</td><td>', $row);
echo '</td></tr>';
}
echo '</table><br>';
@ob_flush();
@flush();
return;
}