0

I have this multibyte arabic text string:

فتكات اكبر تجمع عربي للنساء فقط صحبة وإسلاميات واستشارات وطبخ وزواج وميك اب وتخسيس  
وفضفضة وازياء ومحجبات وهوايات ومول وكليسش مال يهم المرأةفتكات اكبر تجمع عربي للنساء فقط 
صحبة وإسلاميات واستشارات وطبخ وزواج وميك اب وتخسيس وفضفضة وازياء ومحجبات وهوايات ومو

When running PHP mb_strlen function on the string, I get 255 characters which is correct.

Then I tried to insert the string into a column with VARCHAR(255) using PHP Then I selected it again from the database using PHP and the following is the output:

تكات اكبر تجمع عربي للنساء فقط صحبة وإسلاميات واستشارات وطبخ وزواج وميك اب وتخسيس وفضفضة 
وازياء ومحجبات وهوايات ومول وكليسش مال يهم المرأ�

So as you see, almost half of the string has been truncated. I don't know this has to do with MYSQL or PHP output.

Here is my database specs: MYSQL 5+, ENGINE=InnoDB, DEFAULT CHARSET=utf8, utf8_general_ci

And in PHP I'm using PDO statements to connect, insert, and select from the database.

Is there any extra query I need to use when inserting or selecting from database or any PHP function that I must use during insertion or selection?

Michael Samuel
  • 3,820
  • 12
  • 45
  • 85
  • 2
    Look here http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Mihai Sep 22 '14 at 16:39
  • Does the text appear correct (even if truncated) in the database, i.e. when looked at with phpMyAdmin or some such admin utility? Or does it appear as garbage in the database? – deceze Sep 22 '14 at 16:41
  • @deceze it appears as garbage in phpmyadmin but after connecting with charset utf8 in PDO it worked well :) – Michael Samuel Sep 22 '14 at 16:52

1 Answers1

2

I found the answer:

Simply add the following parameter to the MYSQL PDO connection:

mysql:charset=utf8;

And of course make sure to have DEFAULT CHARSET=utf8, utf8_general_ci for database And this meta tag on the page:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Michael Samuel
  • 3,820
  • 12
  • 45
  • 85