Home > Backend Development > PHP Tutorial > SQLSTATE[HY000]: General error: 1366 Incorrect string value

SQLSTATE[HY000]: General error: 1366 Incorrect string value

WBOY
Release: 2016-06-06 20:46:25
Original
3421 people have browsed it

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE4\xB8\x8A\xE5\xAE\x98...' for column 'content' at row 1

mysqld version: 5.6
字符设置成utf-8

后来,根据此帖子:http://drupal.stackexchange.com/questions/88327/pdoexception-sqlstatehy000-general-error-1366-incorrect-string-value-wh
怀疑是mysql 中utf-8 支持的字符集有限,所以改成了 utf8mb4,但是并没有解决问题。

求助各位大侠。

回复内容:

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE4\xB8\x8A\xE5\xAE\x98...' for column 'content' at row 1

mysqld version: 5.6
字符设置成utf-8

后来,根据此帖子:http://drupal.stackexchange.com/questions/88327/pdoexception-sqlstatehy000-general-error-1366-incorrect-string-value-wh
怀疑是mysql 中utf-8 支持的字符集有限,所以改成了 utf8mb4,但是并没有解决问题。

求助各位大侠。

因为是用的PDO,而且SQL语句比较长。就没有把SQL语句给贴出来。

原PHP语句是:BookArticle::create(array('title' => $title, 'content' => $article_content, 'book_id' => $book->id, 'spider_url' => $url)); 我用的是laravel 框架。

执行的时候报错:
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE4\xB8\x8A\xE5\xAE\x98...' for column 'content' at row 1

我想办法clean utf8 code,依然没办法插入。

后来只想打印出SQL,在phpmyadmin里执行一下.

<code> $sql = "insert into book_articles set title='$title',content='$article_content',book_id=$book_id";
</code>
Copy after login

phpmyadmin里的出错信息是 data too long for text ...

把text换成longtext 问题解决。

问题解决的有点慢,原因有两个
1,PDO给里给出的出错信息不够准确。
2,有几篇文章采集时却实有编码问题,这个问题过份的吸引了注意力。

贴sql(字数补丁)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template