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

Jithin Kuriakose
  • 317
  • 5
  • 22
JON
  • 965
  • 2
  • 10
  • 28

5 Answers5

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;
Jaymin
  • 1,643
  • 1
  • 18
  • 39
1

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

Adil Amanat
  • 70
  • 1
  • 5
  • yes i did it , this is my database structure :: prntscr.com/gkj5o6 but it is not work in my case. thanks for answer – JON Sep 13 '17 at 07:17
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

Anup pandey
  • 437
  • 2
  • 9
1

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/

JON
  • 965
  • 2
  • 10
  • 28
Vikas Jangra
  • 175
  • 2
  • 9
1
CREATE TABLE `tableName`(`col` varchar(100) collate utf8_ general_ci);

worked for me

try the collation utf8_general_ci