【问题标题】:Emojis not saved in the database using mysql and node表情符号未使用 mysql 和 node 保存在数据库中
【发布时间】:2021-01-09 11:41:14
【问题描述】:

我想在数据库中保存表情符号

但插入数据库时​​出错

错误:ER_TRUNCATED_WRONG_VALUE_FOR_FIELD:不正确的字符串值:'\xF0\x9F\x98\x9B\xF0\x9F...' 用于第 1 行的列 'text'

我使用了 utf8mb4_unicode_ci 聊天集 utf8mb4 引擎innodb

我也在连接文件中使用过这个

 let connection = mysql.createConnection({
        host                : _CONF.mysql.host,
        user                : _CONF.mysql.user,
        password            : _CONF.mysql.password,
        port                : _CONF.mysql.port,
        database            : _CONF.mysql.database,
        timezone            : _CONF.mysql.timezone,
        charset             : 'utf8mb4',
        collate             : 'utf8mb4_unicode_ci',
        multipleStatements  : _CONF.mysql.multipleStatements
    });

`````
I dont know what I can do next to solve my problem. It would be grateful If anyone can help me out 

【问题讨论】:

  • 列的数据类型是什么?
  • 列的数据类型是varchar
  • 您是否尝试过使用 Binary 或 VarBinary??
  • 还没我会尝试
  • 哦,谢谢你,它解决了我的问题。非常感谢

标签: mysql node.js


【解决方案1】:

如果列的dataType是blob,则将表情符号转换为blob数据并存储为blob。 如果它是一个字符串,您可以将 blob 转换为字符串。您使用 Filereader 模块执行以下操作。

reader.readAsText(blb);

【讨论】:

  • 我在 mysql 列中使用 varbinary 数据类型。并使用 fieldname.toString() 从数据库中获取值。
猜你喜欢
  • 2016-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-08
  • 2017-05-06
  • 1970-01-01
  • 2018-07-02
  • 2020-07-15
相关资源
最近更新 更多