0

I have problems using utf8 in MySQL. I have the following table:

CREATE TABLE IF NOT EXISTS `notas` (
  `id_nota` int(11) NOT NULL AUTO_INCREMENT,
  `nombre_nota` varchar(25) NOT NULL,
  `email_usuario` varchar(100) NOT NULL,
  `descripcion` text NOT NULL,
  `nota_creada_en` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `nota_modificada_en` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `borrado` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_nota`,`email_usuario`),
  KEY `notas_ibfk_1` (`email_usuario`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=6 ;

An the following record stored in the table:

(1, 'Nota1 de esta sólido', 'ricardo@gmail.com', 'Esta es una descripción 1', '2014-05-13 13:07:27', '2014-05-13 13:24:31', 0),

I'm working on PHPMyAdmin and the record above is how is displayed, I mean the text with quotes like "sólido" is displaying fine.

But, finally when I request a query from PHP using PDO:

$con = new PDO('mysql:host='.DB_HOST.';dbname='.DB_DATABASE.';charset=utf8mb4', DB_USER, DB_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4", PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET utf8mb4"));
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

The query returns the record but the contents without quotes, this is what I receive in PHP:

s\u00f3lido instead of sólido

In the past, I've tried utf8 instead of utf8mb4 (according to this post) but I always get the same results.

I've tried many ways to solve it but the problem persists.

And finally: SHOW VARIABLES LIKE 'c%'

Variable_name    Value
character_set_client    utf8mb4
character_set_connection    utf8mb4
character_set_database    utf8mb4
character_set_filesystem    binary
character_set_results    utf8mb4
character_set_server    utf8mb4
character_set_system    utf8
character_sets_dir    /Applications/XAMPP/xamppfiles/share/charsets/
collation_connection    utf8mb4_general_ci
collation_database    utf8mb4_general_ci
collation_server    utf8mb4_general_ci
completion_type    NO_CHAIN
concurrent_insert    AUTO
connect_timeout    10

I really appreciate any kind of help.

Community
  • 1
  • 1
Ricardo
  • 7,921
  • 14
  • 64
  • 111
  • try this answer http://stackoverflow.com/a/584999/2663825 – Dexa May 14 '14 at 09:52
  • @Dexa thanks for reply, but as I said I try with utf8 instead utf8bm4 and nothing change. Plus I've tested with exactly number of params that are using in the post and still failing :( – Ricardo May 14 '14 at 09:56
  • Perhaps your PDO encoding is wrong, see this thread: http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names – Daan May 14 '14 at 09:56
  • 2
    Quotes? Do you mean accents? Whatever, there's no way to get `\u00f3` from `ó` in plain MySQL. You must have some undisclosed code to post-process data (maybe `json_encode()`)—the character is U+00F3 and that's the correct **JavaScript** entity. – Álvaro González May 14 '14 at 09:57
  • 1
    Agreed. **No way** MySQL returns `\u00f3` under any circumstances; unless that's the data you put in in the first place. – deceze May 14 '14 at 09:58
  • 1
    perhaps a duplicate of [Reference: Why are my “special” Unicode characters encoded weird using json_encode?](http://stackoverflow.com/questions/22745662/reference-why-are-my-special-unicode-characters-encoded-weird-using-json-enco) – deceze May 14 '14 at 10:00
  • @deceze You are right, is a clear misconception of mine. Thanks. – Ricardo May 14 '14 at 10:05

0 Answers0