问题
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