mysql> show variables like 'c%'; +--------------------------+-----------------------------------------------+ | Variable_name | Value | +--------------------------+-----------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | h:\wamp\bin\mysql\mysql5.0.45\share\charsets\ | | collation_connection | utf8_general_ci | | collation_database | utf8_unicode_ci | | collation_server | utf8_general_ci | | completion_type | 0 | | concurrent_insert | 1 | | connect_timeout | 5 | +--------------------------+-----------------------------------------------+ 14 rows in set (0.00 sec) mysql> show create database testutf; +----------+------------------------------------------------------------------+ | Database | Create Database | +----------+------------------------------------------------------------------+ | testutf | CREATE DATABASE `testutf` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> show create table nomes; +-------+----------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------+ | Table | Create Table | +-------+----------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------+ | nomes | CREATE TABLE `nomes` ( `id` int(11) NOT NULL auto_increment, `nome` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 | +-------+----------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------+ 1 row in set (0.00 sec)
Tudo utf8, certo?
Meu php ta assim
<meta http-equiv="content-type" content="text/html"; charset="UTF-8"/> <form action="bd.php" method="post" > Nome: <input type="text" name="nome"> <input type="submit" value="Enviar"> </form> <?php header("Content-Type: text/html; charset=UTF-8",true); /** * @author * @copyright 2008 */ $op = $_GET['op']; $host = "localhost"; $login_db = "root"; $senha_db = ""; $database = "testutf"; $nome = $_POST['nome']; $conexao = mysql_connect($host, $login_db, $senha_db) or die(mysql_error()); mysql_select_db($database,$conexao) or die("Erro na seleção do BD"); mysql_query("SET CHARACTER_SET utf8"); mysql_query("SET NAMES utf8"); if ($nome) { $query = "insert into nomes values (NULL, '".$nome."')"; $resultado = mysql_query($query,$conexao); } $query = "Select id, nome from nomes order by id desc limit 10"; $resultado = mysql_query($query,$conexao); while ($linha = mysql_fetch_array($resultado)){ echo $linha[0]." - ".$linha[1]."<br>"; } ?>UTF8 para todos os lados, certo? E o problema continua.
Eu insiro "ááá" no forumlário, e quando vou ler pelo php está "ááá", mas quando vou ler no terminal está ├í├í├í.
Se eu coloco utf8_encode antes de escrever e utf8_decode antes de ler , piora. Quando eu insiro "ááá" no forumlário, vou ler pelo php está ááá, e quando dou um select no terminal está ├â┬í├â┬í├â┬í.
E outra, agora que ta tudo utf8 se eu insiro 'ááá' pelo terminal ele da um warning: | Warning | 1366 | Incorrect string value: '\xA0\xA0\xA0' for column 'nome' at row 1 e não insere nada nos caracteres acentuados. Sera que tem a ver com utf8_general_ci e utf8_unicode_ci?