Answer the question
In order to leave comments, you need to log in
Why aren't emoticons written to the database?
Hello, I am writing a bot in php for telegrams, it must write some data from the user's message to the database. There are emoticons in the message, how to process them correctly? The database and the table have a utf8mb4_unicode_ci comparison, which is supposed to solve the problem, but it doesn't! Runs this on openserver, here is the error:
Fatal error: Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xF0\x9F\x98\x8D",...' for column `music_bot`.`options`.`ads`
Answer the question
In order to leave comments, you need to log in
Found a solution! When connecting to the database, you must also specify the encoding utf8mb4 :
$dsn = "mysql:host=$host;dbname=$db;charset=utf8mb4";
$pdo = new PDO($dsn, $user, $password);
SQLSTATE[22007]: Invalid datetime format
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question