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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6859018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:39:45  来源:igfitidea点击:

Save Data in Arabic in MySQL database

mysqlarabiccharacter-encoding

提问by Romani

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

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

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?

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

采纳答案by Rizwan Shamsher Kaim Khani

To insert Arabic Data manually into your Phpmyadmin.

将阿拉伯语数据手动插入您的 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.

首先,您检查您的数据库、表和列名称是否设置为 utf8。如果这些未设置为 utf8,则首先设置它,然后您可以将阿拉伯语数据插入到 db 表中。

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.

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

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

只需右键单击 db、表、列名称,然后单击更改选项并设置为

Database Chartset = utf8 Database Collation = utf8_general_ci .

数据库图表集 = utf8 数据库整理 = utf8_general_ci 。

Just Enjoy ....

享受就好 ....

回答by Adel Bachene

To read ,write and sort Arabic text in mysql database using php correctly, make sure that:

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

  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_cior utf8_unicode_ci

  1. MySQL 字符集:UTF-8 Unicode (utf8)

  2. MySQL 连接整理: utf8_general_ci

  3. 您的数据库和表排序规则设置为:utf8_general_ciutf8_unicode_ci

Then, add this code in your php script when you connect to db:

然后,当您连接到 db 时,在您的 php 脚本中添加此代码:

mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');

For more details

更多细节

回答by Aditya P Bhatt

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

我们可以使用以下查询将数据库或 db 表转换为 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

Hope it helps !

希望能帮助到你 !

Read More @

阅读更多 @

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

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

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

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

回答by Nadeem Ijaz

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

将数据库表排序规则类型更改为 ,utf8_general_ci并将表字段排序规则更改为utf8_general_ci

enter image description here

enter image description here

回答by sw0x2A

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

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

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

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

回答by Waseem Khalid

Try this code :

试试这个代码:

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

回答by user6121713

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