Skip to content
Databases3 min read

Fix "Incorrect string value" and Arabic text showing as ???

ERROR 1366 (22007): Incorrect string value: '\xD8\xA7\xD9\x84...' for column 'title' at row 1

Short answer

Error 1366 appears when the column or connection character set can't hold the characters you send, such as Arabic into a latin1 column, or emoji into a utf8 column. Convert the database and tables to utf8mb4 with utf8mb4_unicode_ci, and set your app's connection charset to utf8mb4.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What you’re seeing
  2. Causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

The bytes in the message give it away: \xD8\xA7\xD9\x84 is the Arabic «ال» in UTF-8, so the column won’t accept Arabic. Bytes starting with \xF0\x9F are an emoji, which the old utf8 charset has no room for. With strict mode on, MySQL refuses the write with this error; with it off, it silently saves ? in place of each character, which is why Arabic text turns into ????.

What you’re seeing

Symptom Meaning
Error 1366 Strict mode refused characters the column can’t store
???? Connection or column isn’t UTF-8; characters were replaced on save and are lost
العربية UTF-8 text read or stored as latin1; usually repairable
Only emoji fail The column is utf8 (3 bytes) and needs utf8mb4

Causes

  • The database or table was created with the default latin1 charset on an old server or from an old dump.
  • The app’s connection doesn’t set a charset, as in old PHP code without set_charset.
  • Using utf8 instead of utf8mb4, so emoji fail.
  • Importing a file that isn’t UTF-8, or choosing the wrong charset on import.

How to fix it

  1. Back up the database by exporting it before changing anything.

  2. Check the current charset in phpMyAdmin’s SQL tab:

SHOW CREATE TABLE posts;
SHOW VARIABLES LIKE 'character_set%';
  1. Convert the database and tables to utf8mb4:
ALTER DATABASE cpuser_shop CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE posts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Or in phpMyAdmin: select the database, open Operations, choose utf8mb4_unicode_ci under Collation and tick Change all tables collations.

  1. If you see characters like ال, UTF-8 data is sitting in a latin1 column. CONVERT TO would garble it further; go through a binary type instead:
ALTER TABLE posts MODIFY title VARBINARY(255);
ALTER TABLE posts MODIFY title VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  1. Set the connection charset in your app:
// PDO
$pdo = new PDO('mysql:host=localhost;dbname=cpuser_shop;charset=utf8mb4', $user, $pass);
// mysqli
$db->set_charset('utf8mb4');

In Laravel, config/database.php should have 'charset' => 'utf8mb4' and 'collation' => 'utf8mb4_unicode_ci'. In WordPress, in wp-config.php:

define( 'DB_CHARSET', 'utf8mb4' );
  1. When importing, pick utf-8 under Character set of the file on the Import page.

  2. In your pages, add <meta charset="utf-8"> and save files as UTF-8.

Text already saved as ???? won’t come back by converting; re-enter it or re-import it from the original source once the charset is fixed.

Prevention

  • Create every new database and table with utf8mb4_unicode_ci from the start.
  • Always set the charset on the connection rather than relying on the server default.
  • If you hit 1071 Specified key was too long after converting on an older version, shorten indexed columns, for example with Schema::defaultStringLength(191) in Laravel.

On ArabyHost

Databases on ArabyHost run on MariaDB/MySQL with phpMyAdmin, so you can check and convert everything from your browser. Choose utf8mb4_unicode_ci when creating tables for Arabic content, as in the MySQL database guide. The charset itself is explained in utf8mb4 and Arabic text, and WordPress setup in WordPress for Arabic and RTL. If you can’t tell which table or connection is at fault, the Araby AI assistant reads your error log and explains the fix.

FAQ

What's the difference between utf8 and utf8mb4?

MySQL's utf8 stores up to 3 bytes per character: enough for Arabic, but it rejects emoji and some newer symbols. utf8mb4 stores up to 4 bytes and is the right choice for any Arabic site today.

Can I recover text that turned into question marks?

If it was stored as ???? the original characters are gone and can't be converted back. If it shows as strange characters like ال, the data is usually still there and can be repaired after taking a backup.

Which collation should I use for Arabic?

utf8mb4_unicode_ci is a safe, widely used choice. MySQL 8 also has utf8mb4_0900_ai_ci, but some MariaDB versions don't know it and fail with Unknown collation on import, so avoid it if the database may move.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.