How to Save Arabic Data in MySQL Database
A common issue encountered when storing Arabic data in a MySQL database is the appearance of "???" marks instead of Arabic text. To rectify this, a series of steps must be taken.
Check Character Set and Collation
Ensure that the database, table, and columns are using the UTF-8 character set. Use the following queries to verify:
-- Database SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = "your_database_name"; -- Table SELECT CCSA.character_set_name FROM information_schema.`TABLES` T, information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA WHERE CCSA.collation_name = T.table_collation AND T.table_schema = "your_database_name" AND T.table_name = "your_table_name"; -- Column SELECT character_set_name FROM information_schema.`COLUMNS` C WHERE table_schema = "your_database_name" AND table_name = "your_table_name" AND column_name = "your_column_name";
Set UTF-8 for Database, Table, and Column
If any component is not set to UTF-8, follow these steps:
Manually Insert Arabic Data
After setting UTF-8, insert Arabic data directly into the MySQL client using Arabic key sequences. For example, to insert the Arabic text "كتگوری" into the category_name column, use the following query:
INSERT INTO `categories` (`category_name`) VALUES ('كتگوری');
Additional Tips
The above is the detailed content of How to Properly Store Arabic Text in a MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!