1

Arabic language not store in mysql/php

i'm try to insert this query but it is store ???? ???? ?? ????.

INSERT INTO school_name (en_school_name, ar_school_name) VALUES ('some data', 'روضة احمد بنبل')

For solution i have add this

ini_set('default_charset', 'utf-8'); header('Content-type: text/html; charset=utf-8'); mysqli_set_charset($conn,"utf8"); mysqli_query($conn,"SET NAMES 'utf8'"); mysqli_query($conn,'SET CHARACTER SET utf8'); 

and also prefer this Question but not work in my case, Save Data in Arabic in MySQL database

if i'm run query manually it's work fine but when i'm try to insert query with this

$sql = "INSERT INTO school_name (en_school_name, ar_school_name) VALUES ('".$dat_val_en."', '".$dat_val_ar."')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; echo "<br>"; } 

it is store ???? ???? ?? ????. Table structure

enter image description here

3
  • this is my database structure :: prntscr.com/gkj5o6 Commented Sep 13, 2017 at 7:13
  • Checkout this post. This may help you. stackoverflow.com/questions/6859018/… Commented Sep 13, 2017 at 7:14
  • @Pankaj Makwana : yes i did it but not work in my case . Commented Sep 13, 2017 at 7:15

5 Answers 5

3

Change your database structure from

utf8 

To

utf8_unicode_ci 

The charset of the database needs to be utf8_unicode_ci.

Also you can set to database like this also

CREATE DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci; 
Sign up to request clarification or add additional context in comments.

3 Comments

Drop the table and recreate it pls
i have create new table and add utf8_unicode_ci but it is not work prntscr.com/gkjdwj
Maybe it can be helpful
2

To read ,write and sort Arabic text in mysql database using php correctly, make sure that:

1- MySQL charset: UTF-8 Unicode (utf8)

2- MySQL connection collation: utf8_general_ci

3- your database and table collations are set to: utf8_general_ci or utf8_unicode_ci

Then, add this code in your php script when you connect to db:

mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8'); 

for more details: http://www.adviesenzo.nl/examples/php_mysql_charset_fix/

1 Comment

thanks for answer, i did it but it's not work in my case.
1

Make sure you have set you db Character set to UTF-8 And Collation toutf8_general_ci

1 Comment

yes i did it , this is my database structure :: prntscr.com/gkj5o6 but it is not work in my case. thanks for answer
1
CREATE TABLE `tableName` ( `id` int(11) NOT NULL, `comment` text COLLATE utf16_bin NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_bin; 

Note : At a time of creating the table please use below :- DEFAULT CHARSET=utf16 COLLATE=utf16_bin

Comments

1
CREATE TABLE `tableName`(`col` varchar(100) collate utf8_ general_ci); 

worked for me

try the collation utf8_general_ci

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.