I have a database with charset utf8mb4
and collation utf8mb4-bin
. The table and the column to which I'm inserting also have such properties. My PHP file is saved in UTF-8 (without BOM). My $dsn
variable used for a PDO connection looks like this: $dsn = 'mysql:host=127.0.0.1;dbname=vk_comments;port=3306;charset=utf8mb4;connect_timeout=15'
. I'm on PHP 7.2, by the way.
And yet MySQL keeps saying that it got Incorrect string value
. As you can see, I set the proper charset everywhere. What else could be the issue?
ADDITIONAL INFO
Example value before input: 😊
The exact error I'm getting from MySQL: SQLSTATE[HY000]: General error: 1366 Incorrect string value: \u0027\\xF0\\x9F\\x98\\x8A\u0027 for column \u0027comment_text\u0027 at row 1
$sql = "INSERT INTO level_1 (comment_id, user_id, user_name, user_photo, url, comment_text, comment_date) VALUES (:comment_id, :user_id, :user_name, :user_photo, :url, :comment_text, :comment_date)"; $pdo->prepare($sql)->execute($data);
. The variablecomment_text
contains that emoji I specified in the question.