41

I have changed the charset of the tables and of the column, i get the arabic text as ???? marks in MYSQL database

here is the design of the table

  CREATE DATABASE mydb
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;


   CREATE TABLE `categories` (                        
   `category_id` tinyint(2) NOT NULL auto_increment,           
   `category_name` varchar(50)character set utf8 NOT NULL ,  
   PRIMARY KEY  (`category_id`) 


   insert into `mydb`.`categories` 
    (`category_id`, `category_name`)
    values (1,'کتگوری');
   commit;

When I again fire select query it shows ???? as text?

Can anyone tell me where am i doing wrong?

Romani
  • 3,241
  • 4
  • 25
  • 28
  • 3
    Which version of mysql? How are you displaying your text? can you give the code you are using to retrieve the data back? I'm using the same encoding and collation and it works fine for me. – nakhli Jul 28 '11 at 12:36
  • Mysql version 5.0.45. using select query.. select * from poll_categories – Romani Jul 28 '11 at 12:45
  • This works for me in MySQL WB – gbn Jul 28 '11 at 12:45
  • It should work. As answers suggest, make sure that you use the correct encoding in the client side. What client are you using here? – nakhli Jul 28 '11 at 12:48
  • After the connection to MySql in PHP, do `mysql_set_charset('utf8', $con);`. But please consider moving away from `mysql_` functions, they are deprecated and no longer supported in PHP 7. – trincot Feb 01 '16 at 09:41
  • See "question mark" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Nov 15 '19 at 04:58

8 Answers8

36

To insert Arabic Data manually into your Phpmyadmin.

First you check either your database , table and column name is utf8 set or not. If these are not set to utf8 then first you set it then you may insert arabic data into you db table.

YOU MAY CHECK EACH OF THESE BY LOOKING BELOW EXAMPLE.

For Database:

SELECT default_character_set_name FROM information_schema.SCHEMATA S
WHERE schema_name = "schemaname";

For Tables:

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 = "schemaname"
  AND T.table_name = "tablename";

For Columns:

SELECT character_set_name FROM information_schema.`COLUMNS` C
WHERE table_schema = "schemaname"
  AND table_name = "tablename"
  AND column_name = "columnname";

You may easily set utf8 to your tables if you are using SQLYog.

Just right click on db, table, column name and click on alter option and set to

Database Chartset = utf8 Database Collation = utf8_general_ci .

Just Enjoy ....

25

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

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Adel Bachene
  • 974
  • 1
  • 14
  • 34
17

We can convert database or db table to uft8 supportive with below query:

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE columnname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

Hope it helps !

Read More @

https://kb.mediatemple.net/questions/138/Default+MySQL+character+set+and+collation#gs

http://hollyslog.com/technology/how-to-store-arabic-or-hebrew-characters-mysql-database

yaxe
  • 367
  • 5
  • 26
Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104
  • Caution! That last `ALTER` could mangle data even worse. See http://mysql.rjweb.org/doc.php/charcoll#fixes_for_various_cases – Rick James Nov 15 '19 at 04:57
5

Change the database tables collations types to utf8_general_ci and also table fields collations change to utf8_general_ci.

enter image description here

Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130
Nadeem Ijaz
  • 585
  • 1
  • 6
  • 14
3

Try this code :

$conn = new mysqli($server,$username,$password,$dbname);
$conn->set_charset("UTF8");
Antoine Thiry
  • 2,362
  • 4
  • 28
  • 42
  • Hi @Waseem Thank you for answering. Can you please explain why your answer is good and how it solves the question – Tamir Klein Apr 27 '19 at 11:53
3

Make sure that your client software is also using UTF-8.

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

sw0x2A
  • 298
  • 2
  • 7
1
CREATE TABLE mydb.categories         
(category_id tinyint(2) NOT NULL AUTO_INCREMENT
,category_name MEDIUMTEXT NOT NULL
,PRIMARY KEY (category_id)) DEFAULT CHARACTER SET utf8
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

Configuration configuration = new Configuration();

            // Hibernate settings equivalent to hibernate.cfg.xml  properties
            Properties settings = new Properties();
            
            settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
            settings.put(Environment.URL, "jdbc:mysql://localhost:3306/alizidan?useSSL=false&useUnicode=yes&characterEncoding=UTF-8");
            settings.put(Environment.USER, "root");
            settings.put(Environment.PASS, "");
            settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
            // does not work with my sql settings.put(Environment.HBM2DDL_CHARSET_NAME, "UTF-8");

// characterEncoding=UTF-8 at "jdbc:mysql://localhost:3306/alizidan?useSSL=false&characterEncoding=UTF-8" work VERY GOOD

            settings.put(Environment.SHOW_SQL, "true");

            settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");

    //        settings.put(Environment.HBM2DDL_AUTO, "create-drop");

            configuration.setProperties(settings);