I use the PDO library with a MySQL database in PHP, but if I insert any data encoded in UTF-8, like Arabic words, it’s inserted into the database, but as ?????????
All attempts like:
PDO::MYSQL_ATTR_INIT_COMMAND =>"SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci' "
or
$this->connection = new PDO('mysql:host='.DBHOST.';dbname='.DBNAME.';charset=utf8', DBUSER, DBPASS, self::$opt);
or
$this->connection->exec("set names utf8");
still generated unreadable text mess.
In my case, the cause of the problem was: htmlentities used prior to inserting data into a database.
Cyrillic letters were destroyed completely.