-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from startersclan/fix/web-admintasks-fix-tools-…
…resetdbcollations.php-to-convert-db-character-set-to-utf8mb4-and-collation-to-utf8mb4-unicode-ci Fix (web/admintasks): Fix `Admin Panel > Reset All DB Collations` tool to convert DB character set to `utf8mb4` and collation to `utf8mb4_unicode_ci`
- Loading branch information
Showing
2 changed files
with
48 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
Copyleft (L) 2008-20XX Nicholas Hastings ([email protected]) | ||
http://www.hlxcommunity.com | ||
HLstatsX Community Edition is a continuation of | ||
HLstatsX Community Edition is a continuation of | ||
ELstatsNEO - Real-time player and clan rankings and statistics | ||
Copyleft (L) 2008-20XX Malte Bayer ([email protected]) | ||
http://ovrsized.neo-soft.org/ | ||
|
@@ -18,7 +18,7 @@ | |
HLstats - Real-time player and clan rankings and statistics for Half-Life | ||
http://sourceforge.net/projects/hlstats/ | ||
Copyright (C) 2001 Simon Garner | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
|
@@ -49,19 +49,29 @@ | |
|
||
if (isset($_POST['confirm'])) | ||
{ | ||
$convert_to = 'utf8_general_ci'; | ||
$character_set= 'utf8'; | ||
// leo - change to utf8mb4_unicode_ci | ||
//$convert_to = 'utf8_general_ci'; | ||
$convert_to = 'utf8mb4_unicode_ci'; | ||
|
||
// leo - change to utf8mb4 | ||
//$character_set= 'utf8'; | ||
$character_set= 'utf8mb4'; | ||
|
||
if ($_POST['printonly'] > 0) { | ||
echo '<strong>Run these statements against your MySql database</strong><br><br>'; | ||
echo "ALTER DATABASE `".DB_NAME."` DEFAULT CHARACTER SET $character_set COLLATE $convert_to;<br>"; | ||
$rs_tables = $db->query('SHOW TABLES') or die(mysql_error()); | ||
$rs_tables = $db->query('SHOW TABLES') or die(mysqli_error()); | ||
while ($row_tables = $db->fetch_row($rs_tables)) | ||
{ | ||
$table = mysql_real_escape_string($row_tables[0]); | ||
// leo - remove escape because no use! | ||
//$table = mysqli_real_escape_string($row_tables); | ||
$table = $row_tables[0]; | ||
echo "ALTER TABLE `$table` DEFAULT CHARACTER SET $character_set;<br>"; | ||
$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> 'utf8_general_ci'") or die(mysql_error()); | ||
while ($row=mysql_fetch_assoc($rs)) | ||
|
||
// leo - remove hardcoded collation, use variable | ||
//$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> 'utf8_general_ci'") or die(mysqli_error()); | ||
$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> '$convert_to'") or die(mysqli_error()); | ||
while ($row=mysqli_fetch_assoc($rs)) | ||
{ | ||
if ($row['Collation'] == '') | ||
continue; | ||
|
@@ -74,29 +84,34 @@ | |
else if ( $row['Default'] === NULL ) | ||
$default = ' DEFAULT NULL'; | ||
else if ($row['Default']!='') | ||
$default = " DEFAULT '".mysql_real_escape_string($row['Default'])."'"; | ||
$default = " DEFAULT '".mysqli_real_escape_string($row['Default'])."'"; | ||
else | ||
$default = ''; | ||
$field = mysql_real_escape_string($row['Field']); | ||
|
||
$field = mysqli_real_escape_string($row['Field']); | ||
echo "ALTER TABLE `$table` CHANGE `$field` `$field` $row[Type] CHARACTER SET $character_set COLLATE $convert_to $nullable $default;<br>"; | ||
} | ||
} | ||
} else { | ||
echo "Converting database, table, and row collations to utf8:<ul>\n"; | ||
set_time_limit(0); | ||
// leo - remove hardcoded collation, use variable | ||
//echo "Converting database, table, and row collations to utf8:<ul>\n"; | ||
echo "Converting database, table, and row collations to $character_set:<ul>\n"; | ||
set_time_limit(0); | ||
echo '<li>Changing '.DB_NAME.' default character set and collation... '; | ||
$db->query("ALTER DATABASE `".DB_NAME."` DEFAULT CHARACTER SET $character_set COLLATE $convert_to;")or die(mysql_error()); | ||
//$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> 'utf8_general_ci'") or die(mysqli_error()); | ||
$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> '$convert_to'") or die(mysqli_error()); | ||
echo 'OK'; | ||
$rs_tables = $db->query('SHOW TABLES') or die(mysql_error()); | ||
$rs_tables = $db->query('SHOW TABLES') or die(mysqli_error()); | ||
while ($row_tables = $db->fetch_row($rs_tables)) | ||
{ | ||
$table = mysql_real_escape_string($row_tables[0]); | ||
// leo - remove escape because no use! | ||
//$table = mysqli_real_escape_string($row_tables); | ||
$table = $row_tables[0]; | ||
echo "<li>Converting Table: $table ... "; | ||
$db->query("ALTER TABLE `$table` DEFAULT CHARACTER SET $character_set;"); | ||
echo 'OK'; | ||
$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> 'utf8_general_ci'") or die(mysql_error()); | ||
while ($row=mysql_fetch_assoc($rs)) | ||
$rs = $db->query("SHOW FULL FIELDS FROM `$table` WHERE collation is not null AND collation <> 'utf8_general_ci'") or die(mysqli_error()); | ||
while ($row=mysqli_fetch_assoc($rs)) | ||
{ | ||
if ($row['Collation'] == '') | ||
continue; | ||
|
@@ -109,32 +124,36 @@ | |
else if ( $row['Default'] === NULL ) | ||
$default = ' DEFAULT NULL'; | ||
else if ($row['Default']!='') | ||
$default = " DEFAULT '".mysql_real_escape_string($row['Default'])."'"; | ||
// leo - remove escape because no use! | ||
//$default = " DEFAULT '".mysqli_real_escape_string($row['Default'])."'"; | ||
$default = " DEFAULT '".$row['Default']."'"; | ||
else | ||
$default = ''; | ||
|
||
$field = mysql_real_escape_string($row['Field']); | ||
|
||
// leo - remove escape because no use! | ||
//$field = mysqli_real_escape_string($row['Field']); | ||
$field = $row['Field']; | ||
echo "<li>Converting Table: $table Column: $field ... "; | ||
$db->query("ALTER TABLE `$table` CHANGE `$field` `$field` $row[Type] CHARACTER SET $character_set COLLATE $convert_to $nullable $default;"); | ||
echo 'OK'; | ||
} | ||
} | ||
echo '</ul>'; | ||
|
||
echo 'Done.<p>'; | ||
} | ||
|
||
} else { | ||
?> | ||
|
||
?> | ||
|
||
<form method="POST"> | ||
<table width="60%" align="center" border=0 cellspacing=0 cellpadding=0 class="border"> | ||
|
||
<tr> | ||
<td> | ||
<table width="100%" border=0 cellspacing=1 cellpadding=10> | ||
|
||
<tr class="bg1"> | ||
<td class="fNormal"> | ||
|
||
|
@@ -149,7 +168,7 @@ | |
<center><input type="submit" value="Generate commands and do the above"></center> | ||
</td> | ||
</tr> | ||
|
||
</table></td> | ||
</tr> | ||
|
||
|
@@ -158,5 +177,4 @@ | |
|
||
<?php | ||
} | ||
?> | ||
|
||
?> |