1

Just wondering what the best way to update an entire (large) database would be.

Bascially I have inherited a DB which had character issues, with some help I have sorted the character issues going forward (being written in) however the existing data needs cleaning up.

There was a good suggestion that I could use utf_decode to clean all this up - I have tried this on a wrong value in the page itself (when pulled in) and it works great.

As there seems to be a lot of tables, and alot of data, what's the best / quickest way to sweep all the data in the entire DB by using utf_decode ?

Thanks

Thanks for the comments, I can't seem to comment directly so dropping as message in here - I will have a look through and give them a go ! thanks.

4

2 に答える 2

1

MySQL 関数 CONVERT を使用してみましたか? データによっては、「UPDATE mytable SET myfield = CONVERT(myfield USING utf8)」のように、1 つのステートメントでテーブルを更新できる場合があります。

http://dev.mysql.com/doc/refman/5.0/en/charset-convert.html

于 2011-08-09T09:12:52.320 に答える
1

すべてのデータを取得し、変換して次のように挿入します。

INSERT INTO table VALUES (id, text)
(1, 'utf8'), (2, 'utf8'), (3, 'utf8')

複数の INSERT クエリを使用して php ループを実行するよりも高速です。

編集:

素敵な配列を使用すると、これを行うためにスムーズなシステムを実行できます。

$arr = array('users' => array('user_id', 'text', 'username', 'first_name')));

foreach(array_keys($arr) as $h) {
    $query = mysql_query("SELECT * FROM {$h}");
    while($row = mysql_fetch_object($query)) {
        // Loop thingies, utf8_decode then and stuff
    }
    // Then implode them nicely and use above query
}

さらにコード例が必要な場合は教えてください。

于 2011-08-09T09:04:40.420 に答える