即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

Save Data in Arabic in MySQL database

栈溢出 Romani 118℃ 0评论
本文目录
[隐藏]

1.原始问题:Save Data in Arabic in MySQL database

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?

2.被采纳答案

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.

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

3.1.其他高票答案

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

3.1.2.第2个答案

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 `db_table_name` 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

3.1.3.第3个答案

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

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

3.1.4.第4个答案

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

enter image description here

转载请注明:CodingBlog » Save Data in Arabic in MySQL database

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情