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?

6
  • 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. Commented Jul 28, 2011 at 12:36
  • Mysql version 5.0.45. using select query.. select * from poll_categories Commented Jul 28, 2011 at 12:45
  • This works for me in MySQL WB Commented Jul 28, 2011 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? Commented Jul 28, 2011 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. Commented Feb 1, 2016 at 9:41

8 Answers 8

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 ....

Sign up to request clarification or add additional context in comments.

2 Comments

specially, please check the individual column character encoding, that's what had me scratching my head for quiet long.
Simpler with just SHOW CREATE TABLE tablename;
26

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

1 Comment

Don't use the deprecated mysql_query; switch to mysqli or PDO.
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

1 Comment

Caution! That last ALTER could mangle data even worse. See mysql.rjweb.org/doc.php/charcoll#fixes_for_various_cases
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

Comments

4

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

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

Comments

3

Try this code :

$conn = new mysqli($server,$username,$password,$dbname); $conn->set_charset("UTF8"); 

1 Comment

Hi @Waseem Thank you for answering. Can you please explain why your answer is good and how it solves the question
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 

Comments

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); 

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.