php 如何用印地语以unicode存储数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12435867/
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-25 03:34:21  来源:igfitidea点击:

How to store the data in unicode in hindi language

phpmysqlunicodehindi

提问by nilesh

I am using PHPand MySQLfor an application.

我正在使用PHPMySQL用于应用程序。

Questions are:

问题是:

  1. How to store data in MySQL???? ?????? ??????readable format or नà¤?à¤2à¥?à¤? र à¤aà¥à¤?format

  2. When user enters data in a textbox and clicks on submit, at that time we get data in different format. What we need to do should we convert and store in MySQLin readable format.

  1. 如何以MySQL???? ?????? ??????可读格式或नà¤?à¤2à¥?à¤? र à¤aà¥à¤?格式存储数据

  2. 当用户在文本框中输入数据并点击提交时,我们会得到不同格式的数据。我们需要做的是转换并MySQL以可读格式存储。

回答by rajukoyilandy

Choose utf8 character set and utf8_general_cicollation.

选择 utf8 字符集和utf8_general_ci排序规则。

Obviously, Collation of the field (to which you want to store Hindi text) should be utf8_general_ci.

显然,字段的排序规则(您要存储印地语文本的位置)应该是utf8_general_ci.

To alter your table field, run

要更改您的表字段,请运行

ALTER TABLE `<table_name>` CHANGE `<field_name>` `<field_name>` VARCHAR(100) 
CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT NULL;

Once you've connected to database, run the following statement at first

连接到数据库后,首先运行以下语句

mysql_set_charset('utf8');

Eg:

例如:

//setting character set
mysql_set_charset('utf8');

//insert Hindi text
mysql_query("INSERT INTO ....");

To retrieve data

检索数据

//setting character set
mysql_set_charset('utf8');

//select Hindi text
mysql_query("SELECT * FROM ....");

Before you printing any unicode text (say Hindi text) on browser, you should have to set content type of that page by adding a meta tag

在浏览器上打印任何 unicode 文本(例如印地语文本)之前,您应该通过添加元标记来设置该页面的内容类型

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Eg:

例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example Unicode</title>
</head>

<body>
<?php echo $hindiText; ?>
</body>
</html>

Update:

更新

mysql_query("SET CHARACTER SET utf8") has changed tomysql_set_charset('utf8'); This is the preferred way to change the charset. Using mysql_query() to set it (such as SET NAMES utf8) is not recommended. See http://php.net/manual/en/function.mysql-set-charset.php*

mysql_query("SET CHARACTER SET utf8") has changed tomysql_set_charset('utf8'); 这是更改字符集的首选方法。不建议使用 mysql_query() 来设置它(例如 SET NAMES utf8)。见http://php.net/manual/en/function.mysql-set-charset.php*

回答by Sorter

You only need to run the following command on the table.

您只需要在表上运行以下命令。

ALTER TABLE <tablename> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Note: You should use utf8_general_ciinstead of ut8_unicode_ci, as it is said to be faster. What's the difference between utf8_general_ci and utf8_unicode_ci

注意:您应该使用utf8_general_ci而不是ut8_unicode_ci,因为据说它更快。 utf8_general_ci 和 utf8_unicode_ci 有什么区别

回答by Dinesh Sarak

There is no need to alter table with charset. but your database should be with utf8_unicode_ci.

无需使用字符集更改表。但你的数据库应该是 utf8_unicode_ci。

while connecting with database just need to add this line only." mysqli_set_charset($con, 'utf8')"

连接数据库时只需要添加这一行。" mysqli_set_charset($con, 'utf8')"

    $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
    mysqli_set_charset($con, 'utf8');
    mysqli_query($con, $sql);

回答by Jiten Basnet

After converting COLLATE to utf8_general_ci use this line mysqli_set_charset($con, 'utf8'); in between $con and mysqli_query() below your query.

将 COLLATE 转换为 utf8_general_ci 后使用这一行 mysqli_set_charset($con, 'utf8'); 在您的查询下方的 $con 和 mysqli_query() 之间。

$con= mysqli_connect($host,$user,$pass,$db) or die('Unable to connect');

$con= mysqli_connect($host,$user,$pass,$db) or die('无法连接');

$sql="your query.. ";

$sql="您的查询..";

mysqli_set_charset($con, 'utf8');

mysqli_set_charset($con, 'utf8');

$result=mysqli_query($con,$sql);

$result=mysqli_query($con,$sql);