dourang6423 2014-05-14 09:48
浏览 37

PHP,Mysql和UTF-8和引号

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用