S
S
Soft_touch_plastic2021-06-12 17:00:10
PHP
Soft_touch_plastic, 2021-06-12 17:00:10

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

3 answer(s)
S
Soft_touch_plastic, 2021-06-12
@Soft_touch_plastic

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);

D
Denis Yuriev, 2021-06-12
@dyuriev

SQLSTATE[22007]: Invalid datetime format

And what does emoticons have to do with it?
Everything is indicated in the text of the error, neither add nor subtract

S
SagePtr, 2021-06-12
@SagePtr

The database and the table have a utf8mb4_unicode_ci comparison
It should also be near the fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question