mysql_convert_unicode.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  3. require_once "../sessions.php";
  4. require_once "../sanity_check.php";
  5. require_once "../functions.php";
  6. require_once "../config.php";
  7. require_once "../db.php";
  8. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  9. init_connection($link);
  10. login_sequence($link);
  11. $owner_uid = $_SESSION["uid"];
  12. if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
  13. $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
  14. render_login_form($link);
  15. exit;
  16. }
  17. ?>
  18. <html>
  19. <head>
  20. <title>MySQL Charset Converter</title>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link rel="stylesheet" type="text/css" href="utility.css">
  23. <script type="text/javascript" src="localized_js.php"></script>
  24. </head>
  25. <body>
  26. <script type='text/javascript'>
  27. function confirmOP() {
  28. return confirm(__("Update the database?"));
  29. }
  30. </script>
  31. <div class="floatingLogo"><img src="images/ttrss_logo.png"></div>
  32. <h1><?php echo __("MySQL Charset Updater") ?></h1>
  33. <?php
  34. $op = $_POST["op"];
  35. if (DB_TYPE != "mysql") {
  36. print_warning(__("This script is for Tiny Tiny RSS installations with MySQL backend only."));
  37. print "<form method=\"GET\" action=\"logout.php\">
  38. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  39. </form>";
  40. } else if (!$op) {
  41. print_warning(__("Please backup your database before proceeding."));
  42. print "<p>" . __("This script will convert your Tiny Tiny RSS database to UTF-8.
  43. Depending on current database charset you may experience data corruption (lost accent characters, etc.).
  44. After update, you'll have to set <b>MYSQL_CHARSET</b> option in config.php to 'utf8'.") . "</p>";
  45. print "<form method='POST'>
  46. <input type='hidden' name='op' value='do'>
  47. <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
  48. </form>";
  49. } else if ($op == "do") {
  50. print "<p>".__("Converting database...")."</p>";
  51. db_query($link, "BEGIN");
  52. db_query($link, "SET FOREIGN_KEY_CHECKS=0");
  53. $result = db_query($link, "SHOW TABLES LIKE 'ttrss%'");
  54. while ($line = db_fetch_assoc($result)) {
  55. $vals = array_values($line);
  56. $table = $vals[0];
  57. $query = "ALTER TABLE $table CONVERT TO
  58. CHARACTER SET 'utf8'";
  59. print "<p class='query'>$query</p>";
  60. db_query($link, $query);
  61. }
  62. db_query($link, "SET FOREIGN_KEY_CHECKS=1");
  63. db_query($link, "COMMIT");
  64. print "<form method=\"GET\" action=\"logout.php\">
  65. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  66. </form>";
  67. }
  68. ?>
  69. </body>
  70. </html>