[PHP] 解决mysql下1366 Incorrect string value错误
2023-02-18 15:41:30 时间
这个错误是字符编码的问题 , 因为内容里有可能有表情等特殊字符 , 需要使用utf8mb4编码
重点还有一个是 , 在php代码中连接上mysql后一定要执行一下 set name utf8mb4 否则也是不行的
比如下面这个表的字符编码
create table laruence( id int unsigned auto_increment, title varchar(225) not null default '', link varchar(225) not null default '', content text, primary key id_idx(id), unique key link_idx(link) )engine=innodb charset=utf8mb4;
比如下面的PHP代码:
$this->pdo = new \PDO($this->dsn, $this->user, $this->password,array( \PDO::ATTR_PERSISTENT => $this->persistent )); $this->pdo->setAttribute( \PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); $this->pdo->exec("set names utf8mb4");
相关文章
- Tampermonkey for Mac(油猴Safari浏览器插件)中文版v 4.17.6162
- Redis分布式锁的10个坑
- 如何解决 Redis 数据倾斜、热点等问题
- 免费给自己的网站加 HTTPS
- iterm2 快捷键(转载)
- Too many authentication failures for xxxx_username
- peewee insert 数据时报错:'buffer' object has no attribute 'translate'
- virtualenv 虚拟环境报错:setuptools pip wheel failed with error code 1
- supervisor 安装、配置、常用命令
- _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
- [MySQL]支持 emoji(字符集问题)
- [MySQL]长连接和短链接(转载)
- 解决 InsecurePlatformWarning: A true SSLContext object is not available.
- Mac总是自动启动脚本
- Max retries exceeded with url
- brew tap homebrew-science fails
- 持续集成是什么?(转载)
- [编辑器]vim常用操作
- Mac下中文输入法突然没了选字框
- install dm.xmlsec.binding 失败