source: trunk/junk/change-collation.php @ 1184

Revision 852, 1.2 KB checked in by cdleonard@…, 4 years ago (diff)

svn:eol-style native in trunk. Also svn:executable on all scripts

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3
4// Database host.
5define("DB_HOST", 'db');
6
7// Database name.
8define("DB_NAME", 'infoarena');
9
10// Database user.
11define("DB_USER", 'infoarena');
12
13// Database password
14define("DB_PASS", 'sha0lyn');
15
16// New charset/collation for the database.
17define("DB_CHARSET", 'latin1');
18define("DB_COLLATION", 'latin1_general_ci');
19
20// Don't modify below.
21
22mysql_connect(DB_HOST, DB_USER, DB_PASS);
23mysql_select_db(DB_NAME);
24
25function db_query($command) {
26    $res = mysql_query($command);
27    if ($res === false) {
28        print(mysql_error());
29        die();
30    }
31    return $res;
32}
33
34function db_fetch_all($qres) {
35    $res = array();
36    while (true) {
37        $row = mysql_fetch_assoc($qres);
38        if ($row === false) {
39            return $res;
40        }
41        $res[] = $row;
42    }
43}
44
45$table_list = db_fetch_all(db_query("SHOW TABLES"));
46foreach ($table_list as $table_list_row) {
47    $table = array_values($table_list_row);
48    $table = $table[0];
49
50    $esctable = mysql_real_escape_string($table);
51    $query = sprintf("ALTER TABLE `%s` CONVERT TO CHARACTER SET %s COLLATE %s",
52            $esctable, DB_CHARSET, DB_COLLATION);
53    db_query($query);
54}
55
56?>
Note: See TracBrowser for help on using the repository browser.