Convert arabic / japanese to mySQL in php?

There are foreign characters in my mySQL database that are Arabic or Japanese,

تظاهرات در خیابان آذربایجان

and they look great in phpMyAdmin (db utf8_general_ci db column structure), but when I try to repeat them from mySQL query, I get ???. Since I am rewriting this back to an AJAX request, how do I send characters back to go through the encoding?

Thanks from a very confused international student.

+4
source share
1 answer

It can be one or both of these problems:

The output encoding is not set correctly. Put this in your .php file (at the top, before sending any output):

header("Content-Type: text/html; charset=UTF-8"); 

Your database connection / communication encoding (not quite sure what to call) is not set up correctly. Put this after you connect to the database, but before retrieving any data:

 mysql_query('SET NAMES utf8'); // (or equivalent) 

This ensures that communication between php and mysql is also done in utf8.

+3
source

Source: https://habr.com/ru/post/1339918/


All Articles