Domanda

Non ho i seguenti dati: Trollhättan

  • Se io stampare e impostare l'intestazione a utf-8, allora questo è l'output nel browser.

  • Se non mi configurazione del utf-8 nell'intestazione, Trollhättan. Tuttavia, quando sto memorizzazione dei dati nel database e il controllo attraverso phpmyadmin, sto ottenendo la seguente stringa:. Trollhättan

  • Quando sto installando l'intestazione a utf-8, sto ottenendo questa stringa: Trollhättan accanto a questo Trollhättan.

Poiché la tabella è latin1_swedish_ci, devo usare nella UTF-8 tavolo?

È stato utile?

Soluzione

Ecco l'elenco delle regole di confronto in UTF-8

mysql> select * from information_schema.collations where CHARACTER_SET_NAME = 'utf8';
+--------------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME     | CHARACTER_SET_NAME | ID  | IS_DEFAULT | IS_COMPILED | SORTLEN |
+--------------------+--------------------+-----+------------+-------------+---------+
| utf8_general_ci    | utf8               |  33 | Yes        | Yes         |       1 |
| utf8_bin           | utf8               |  83 |            | Yes         |       1 |
| utf8_unicode_ci    | utf8               | 192 |            | Yes         |       8 |
| utf8_icelandic_ci  | utf8               | 193 |            | Yes         |       8 |
| utf8_latvian_ci    | utf8               | 194 |            | Yes         |       8 |
| utf8_romanian_ci   | utf8               | 195 |            | Yes         |       8 |
| utf8_slovenian_ci  | utf8               | 196 |            | Yes         |       8 |
| utf8_polish_ci     | utf8               | 197 |            | Yes         |       8 |
| utf8_estonian_ci   | utf8               | 198 |            | Yes         |       8 |
| utf8_spanish_ci    | utf8               | 199 |            | Yes         |       8 |
| utf8_swedish_ci    | utf8               | 200 |            | Yes         |       8 |
| utf8_turkish_ci    | utf8               | 201 |            | Yes         |       8 |
| utf8_czech_ci      | utf8               | 202 |            | Yes         |       8 |
| utf8_danish_ci     | utf8               | 203 |            | Yes         |       8 |
| utf8_lithuanian_ci | utf8               | 204 |            | Yes         |       8 |
| utf8_slovak_ci     | utf8               | 205 |            | Yes         |       8 |
| utf8_spanish2_ci   | utf8               | 206 |            | Yes         |       8 |
| utf8_roman_ci      | utf8               | 207 |            | Yes         |       8 |
| utf8_persian_ci    | utf8               | 208 |            | Yes         |       8 |
| utf8_esperanto_ci  | utf8               | 209 |            | Yes         |       8 |
| utf8_hungarian_ci  | utf8               | 210 |            | Yes         |       8 |
| utf8_sinhala_ci    | utf8               | 211 |            | Yes         |       8 |
+--------------------+--------------------+-----+------------+-------------+---------+
22 rows in set (0.03 sec)

latin1_swedish_ci appartiene alla latin1

mysql> select * from information_schema.collations where COLLATION_NAME = 'latin1_swedish_ci';
+-------------------+--------------------+----+------------+-------------+---------+
| COLLATION_NAME    | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN |
+-------------------+--------------------+----+------------+-------------+---------+
| latin1_swedish_ci | latin1             |  8 | Yes        | Yes         |       1 |
+-------------------+--------------------+----+------------+-------------+---------+
1 row in set (0.03 sec)

L'utf8 più vicino per la collazione è ID 200

mysql> select * from information_schema.collations where ID = 200;
+-----------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME  | CHARACTER_SET_NAME | ID  | IS_DEFAULT | IS_COMPILED | SORTLEN |
+-----------------+--------------------+-----+------------+-------------+---------+
| utf8_swedish_ci | utf8               | 200 |            | Yes         |       8 |
+-----------------+--------------------+-----+------------+-------------+---------+
1 row in set (0.00 sec)

CAVEAT

Si può sperimentare con latin1, modificare il set di caratteri e collazione della singola colonna della tabella, o forse entrambe le cose. Per lo meno, utilizzare latin1 per la visualizzazione in phpMyAdmin.

Si potrebbe tweek e sperimentare rendendo l'intero database di un set di caratteri specifici e collazione utilizzando ALTER DATABASE .

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;

Assicurati di fare un backup del database e caricarlo in un dev / staging DB e quindi eseguire ALTER DATABASE contro dev / messa in scena.

Altri suggerimenti

È necessario fare in modo che quando si "Memorizzazione dei dati nel database", il client che si sta usando uso utf8. Quindi impostando il http intestazione per utf8 completa il viaggio di andata.

La sorpresa è che non importa molto quello set di caratteri viene utilizzato nel database (anche se potrebbe anche essere comodo per che, per essere utf8 troppo).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top