在MySQL数据库中以阿拉伯语保存数据

时间:2011-07-28 12:32:23

标签: mysql arabic character-encoding

我已经更改了表格和列的字符集,我将阿拉伯语文本更改为???? MYSQL数据库中的标记

这是表格的设计

  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;

当我再次点击选择查询时,它会显示????作为文字?

谁能告诉我我哪里做错了?

8 个答案:

答案 0 :(得分:28)

手动将阿拉伯数据插入Phpmyadmin。

首先检查数据库,表和列名是否设置为utf8。 如果这些没有设置为utf8,那么首先你设置它然后你可以将阿拉伯数据插入你的db表。

您可以通过以下示例查看其中的每一个。

对于数据库:

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

表格:

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

对于列:

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

如果您使用的是SQLYog,可以轻松地将utf8设置为表。

右键单击db,table,column name并单击alter option并设置为

数据库Chartset = utf8 数据库整理= utf8_general_ci。

享受....

答案 1 :(得分:20)

使用php正确读取,编写和排序mysql数据库中的阿拉伯文本,请确保:

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

  2. MySQL连接排序规则:utf8_general_ci

  3. 您的数据库和表格排名设置为:utf8_general_ciutf8_unicode_ci

  4. 然后,在连接到db:

    时,在PHP脚本中添加此代码
    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET CHARACTER SET utf8');
    

    For more details

答案 2 :(得分:9)

我们可以使用以下查询将数据库或数据库表转换为支持uft8:

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

希望它有所帮助!

阅读更多@

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 :(得分:4)

将数据库表归类类型更改为utf8_general_ci,并且表字段归类更改为utf8_general_ci

enter image description here

答案 4 :(得分:3)

确保您的客户端软件也使用UTF-8。

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

答案 5 :(得分:0)

尝试此代码:

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

答案 6 :(得分:0)

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

答案 7 :(得分:0)

配置配置 = 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" 工作非常好

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

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

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

            configuration.setProperties(settings);