Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value

荒凉一梦 提交于 2020-01-23 02:33:30

问题


This is the error I am getting.

PDOException: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xF0\x9F\x98\xB3' for column 'string' at row 1'

I know the problem here. The column table is using utf8. The utf8 encoding cannot store 4 byte characters so it errors. A way to get around this could be to use utf8mb4 instead.

My question instead is about the error message. We are using MariaDB. Why does it say "Invalid datetime format" in the error message? This is a text field. There is nothing to do with datetime in the query being run.

This "Invalid datetime format" comes up often for a variety of errors but seems unrelated to the actual source of the error.


回答1:


Yes, I've seen this before.

I suppose it's a bug on the mariadb side, where all errors on the incorrect values are dubbed as "incorrect datetime value".

I see no harm here though beside a little confusion. Just keep in mind the issue and treat it as "incorrect text value"



来源:https://stackoverflow.com/questions/39750417/uncaught-exception-pdoexception-with-message-sqlstate22007-invalid-datetim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!