本文介绍了如何插入多语言字符串数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到NVARCHAR类型,但目前还没有在我的免费托管服务器的phpmyadmin的窗口命名NVARCHAR任何类型。 (000webhost.com)

我可以手动插入像琴弦തിരുവനന്തപുരം∙മൂന്നുവർഷങ്ങൾക്കുമുൻപ്മൊയ്തീന്റെകഥയുടെവൺലൈൻകേട്ടപ്പൊഴേഎന്ന്നിന്റെമൊയ്തീൻസിനിമചെയ്യാൻതീരുമാനിച്ചിരുന്നു到数据库中的行,但是当我使用一个PHP做同样的插入的数据变得像

&放大器;#3368;&放大器;#3405;&放大器;#3375;&放大器;#3394;&放大器;#3361;&放大器;#3453;&放大器;#3385;&放大器;#3391;&放大器;#8729; &放大器;#3335;&放大器;#3368;&放大器;#3405;&放大器;#3364;&放大器;#3405;&放大器;#3375;

我使用的排序规则utf8_uni code_ci现在VARCHAR类型(1000)。

我的PHP code

 头('内容类型:text / html的;字符集= utf-8');
$ CON =新的mysqli(mysql1.000webhost.com,a9798817_person
starting1,a9798817_person);
$ CON-> set_charset('UTF8');
如果($ CON-> connect_error){
    死(连接失败:$ CON-> connect_error);
}
如果(空($ _ FILES [IMAGE2] [名称])及!&安培;!空($ _ FILES [的Image3] [名称]))
{        回声的内容与第一,第二和第三图像上传;
        $ file_name1 = $ _ FILES [此搜索] [名称];
        $ target_path1 =图片/\".$ file_name1;
        $ temp_name1 = $ _ FILES [此搜索] [tmp_name的值];
        $ file_name2 = $ _ FILES [IMAGE2] [名称];
        $ target_path2 =图片/\".$ file_name2;
        $ temp_name2 = $ _ FILES [IMAGE2] [tmp_name的值];
        $ file_name3 = $ _ FILES [的Image3] [名称];
        $ target_path3 =图片/\".$ file_name3;
        $ temp_name3 = $ _ FILES [的Image3] [tmp_name的值];    $内容=തിരുവനന്തപുരം∙മൂന്നുവർഷങ്ങൾക്കുമുൻപ്മൊയ്തീന്റെകഥയുടെവൺലൈൻകേട്ടപ്പൊഴേഎന്ന്നിന്റെമൊയ്തീൻസിനിമചെയ്യാൻതീരുമാനിച്ചിരുന്നു
    打印($内容);
    如果(move_uploaded_file($ temp_name1,$ target_path1)及&放大器; move_uploaded_file(temp_name2,$ target_path2)及&放大器; move_uploaded_file($ temp_name3,$ target_path3))
    {
    $ query_upload =INSERT INTO MAINNEWS(此搜索,图像2,图像3,内容)VALUES('$ file_name1','$ file_name2','$ file_name3','$内容');
    $ CON->查询($ query_upload)或死亡(错误在$ query_upload == ---->中.mysql_error());
    }
    其他
    {
    退出(错误在上传该服务器上的图像);
    }
}

我得到一个输出

 与内容第一,第二和第三图像上传തിരുവനന്തപുരം∙മൂന്നുവർഷങ്ങൾക്കുമുൻപ്മൊയ്തീന്റെകഥയുടെവൺലൈൻകേട്ടപ്പൊഴേഎന്ന്നിന്റെമൊയ്തീൻസിനിമചെയ്യാൻതീരുമാനിച്ചിരുന്നു

但在数据库中,,内容字段显示像

&放大器;#3368;&放大器;#3405;&放大器;#3375;&放大器;#3394;&放大器;#3361;&放大器;#3453;&放大器;#3385;&放大器;#3391;&放大器;#8729;等等

请注意:其实有NOT BETWEEN数量和空间; ,,我把它特意否则它会显示一般都喜欢ന്യൂഡൽഹി∙


解决方案

本笔记包含了一些介绍说明。

RDBMS表服务器的一些品牌和型号使用 NVARCHAR()数据类型来存储UNI code数据。 UNI code是存储喜欢多语言的数据,你的情况的好方法,僧伽罗人(正确吗?)和英语。

但MySQL的的没有 NVARCHAR()数据类型的。相反,你可以在表中创建列时,指定字符集用来存储的内容。 UTF8字符集是好这一点。您也可以指定排序规则(如 utf8_general_ci utf8_sinhala_ci 。这些归类的没有任何效果的上数据的方式被存储,仅在它是如何排序和筛选

MySQL的(如所有品牌和台服务器的型号)是一种客户端 - 服务器系统。服务器保存的数据,并满足查询。您的必须使用一个客户端的插入或从服务器获取数据。该客户端处理上,再次对出路的方式您的数据。

您的问题说你手工插入一些数据到服务器。 precisely讲,这是完全不可能的。您必须使用某些客户端软件,即使是在mysql命令行程序。为了解决你的问题,你需要找出你使用什么客户端软件为所谓的手动操作。为什么?由于客户端软件处理数据。

调用的程序的phpMyAdmin 是这些客户端程序之一。不幸的是,这是非常困难的使用故障排除这类问题。为什么?它使用网络浏览器来呈现其输出。世界包含重新presenting多语言字符的方法很多。 Web浏览器是专为信息使用者。他们尽自己所能来猜测用户想看到的。

在具体地,Web浏览器接受字符$ C $光盘作为HTML实体,并为观众翻译。例如,&放大器; LT;&放大器;放大器;&放大器; GT 呈现为<&安培;> 。而且,你的数据串

<$p$p><$c$c>&#3368;&#3405;&#3375;&#3394;&#3361;&#3453;&#3385;&#3391;&#8729;

呈现为ന്യൂഡൽഹി∙

(谁建的堆栈溢出跑到带来很大的麻烦,以确保我们能显示出这些文字的HTML实体的人。)

大部分的Uni code字符可以重新presented作为一个16位的项目,例如(十六进制)3368再度presents 。他们还可以重新psented因为这些HTML实体$ P $:十六进制数$ P $由&放pceded;#其次为分号。在浏览器中(即在phpMyAdmin),您将无法除非你用查看源分辨...

本HTML实体的东西可以让各种信息,以便psented为7位流重新$ P $(ASCII,与老派的电传打字机兼容)字符。它派上用场的数据交换。不过,这并不与MySQL校对工作。

所以,这里的东西。在你的数据库中的信息似乎已经EN codeD中的HTML实体形式(&放大器;#3368; ),而不是单向code僧伽罗语。你的任务是要弄清楚如何发生的。

PHP程序可以翻译UTF文本实体化与ヶ辆文本()。其它语言也有类似的功能。很明显,你用来把你的数据到MySQL软件这样做。

这是实体化的文本,一旦你从MySQL中检索它,可以通过 html_de code翻译回单code()

你怎么能弄清楚什么是存储在MySQL的?试试这个:

  SELECT关口,CHARACTER_LENGTH(COL),HEX(COL)

这将显示你的客户端山坳 presented的价值。它也将显示中的字符列和数量栏的十六进制编码。字符的一个实体化字符数为6,而在单向code字符的数量是一。

I read about NVARCHAR type, but there aren't any type named NVARCHAR in the phpmyadmin window of my free hosting server. (000webhost.com)

I can manually insert strings like 'തിരുവനന്തപുരം∙ മൂന്നു വർഷങ്ങൾക്കു മുൻപ് മൊയ്തീന്റെ കഥയുടെ വൺലൈൻ കേട്ടപ്പൊഴേ എന്ന് നിന്റെ മൊയ്തീൻ സിനിമ ചെയ്യാൻ തീരുമാനിച്ചിരുന്നു ' to database rows but when i use a php to do the same the inserted data becomes something like

&#3368 ;&#3405 ;&#3375 ;&#3394 ;&#3361 ;&#3453 ;&#3385 ;&#3391 ;&#8729 ; &#3335 ;&#3368 ;&#3405 ;&#3364 ;&#3405 ;&#3375 ;

i am using collation utf8_unicode_ci and type VARCHAR(1000) now.

my php code

header('Content-Type: text/html; charset=utf-8');
$con = new mysqli("mysql1.000webhost.com", "a9798817_person",
"starting1", "a9798817_person");
$con->set_charset('utf8');


if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}


if (!empty($_FILES["image2"]["name"])&&!empty($_FILES["image3"]["name"]))
{

        echo"first second and third image with content is uploaded";
        $file_name1=$_FILES["image1"]["name"];
        $target_path1 = "images/".$file_name1;
        $temp_name1=$_FILES["image1"]["tmp_name"];
        $file_name2=$_FILES["image2"]["name"];
        $target_path2 = "images/".$file_name2;
        $temp_name2=$_FILES["image2"]["tmp_name"];
        $file_name3=$_FILES["image3"]["name"];
        $target_path3 = "images/".$file_name3;
        $temp_name3=$_FILES["image3"]["tmp_name"];

    $content="തിരുവനന്തപുരം∙ മൂന്നു വർഷങ്ങൾക്കു മുൻപ് മൊയ്തീന്റെ കഥയുടെ വൺലൈൻ കേട്ടപ്പൊഴേ എന്ന് നിന്റെ മൊയ്തീൻ സിനിമ ചെയ്യാൻ തീരുമാനിച്ചിരുന്നു "
    print($content);
    if(move_uploaded_file($temp_name1, $target_path1)&&move_uploaded_file($temp_name2, $target_path2)&&move_uploaded_file($temp_name3, $target_path3))
    {
    $query_upload="INSERT INTO MAINNEWS (image1,image2,image3,content) VALUES ('$file_name1','$file_name2','$file_name3','$content')";
    $con->query($query_upload) or die("error in $query_upload == ----> ".mysql_error());
    }
    else
    {
    exit("Error While uploading image on the server");
    }
}

i get an output as

first second and third image with content is uploadedതിരുവനന്തപുരം∙ മൂന്നു വർഷങ്ങൾക്കു മുൻപ് മൊയ്തീന്റെ കഥയുടെ വൺലൈൻ കേട്ടപ്പൊഴേ എന്ന് നിന്റെ മൊയ്തീൻ സിനിമ ചെയ്യാൻ തീരുമാനിച്ചിരുന്നു

but in the database,, the content field is shown like

&#3368 ;&#3405 ;&#3375 ;&#3394 ;&#3361 ;&#3453 ;&#3385 ;&#3391 ;&#8729 ; etc

NOTE : ACTUALLY THERE AREN'T ANY SPACES BETWEEN NUMBER AND ';' ,, I PUT IT INTENTIONALLY OTHERWISE THE IT DISPLAYS NORMALLY LIKE ന്യൂഡൽഹി∙

解决方案

This note contains some introductory explanations.

Some makes and models of rdbms table server use the NVARCHAR() data type to store unicode data. Unicode is a good way to store multiple-language data like, in your case, Sinhalese (correct?) and English.

But MySQL does not have the NVARCHAR() data type. Instead, you may, when creating columns in tables, specify the character set to use to store the contents. The UTF8 character set is good for this. You can also specify a collation (like utf8_general_ci or utf8_sinhala_ci. These collations have no effect on the way data is stored, only on how it is sorted and filtered.

MySQL (like all makes and models of table server) is a client-server system. The server holds the data and satisfies queries. You must use a client to insert or retrieve data from the server. The client handles your data on the way in and again on the way out.

Your question says you "manually inserted" some data into the server. Precisely speaking, that is entirely impossible. You must have used some client software, even if it was the mysql command line program. To solve your problem, you will need to figure out what client software you used for that so-called "manual" operation. Why? Because client software handles your data.

The program called phpMyadmin is one of those client programs. Unfortunately, it is very difficult to use for troubleshooting your kind of problem. Why? It uses a web browser to render its output. The world contains many ways of representing multiple-language characters. Web browsers are built for users of information. They do their best to guess what a user would like to see.

In particular, Web browsers accept characters coded as HTML entities, and translate them for the viewer. For example, &lt;&amp;&gt is rendered as <&>. And, your data string

&#3368;&#3405;&#3375;&#3394;&#3361;&#3453;&#3385;&#3391;&#8729;

renders as ന്യൂഡൽഹി∙.

(The people who built Stack Overflow went to a great deal of trouble to make sure we can show these literal html entities.)

Most Unicode characters can be represented as a 16-bit item, e.g. hex 3368 represents . They also can be represented as these html entities: the hex number preceded by &# and followed by semicolon. In a browser (that is, in phpmyadmin) you won't be able to tell the difference unless you use View Source...

This html entity stuff allows all kinds of information to be represented as a stream of 7-bit (ASCII, compatible with the old-school teletype machines) characters. It comes in handy for data interchange. But it doesn't work with MySQL collations.

So, here's the thing. The information in your database seems to have been encoded in the html entities form (&#3368;) rather than in the unicode for Sinhalese. Your task is to figure out how that happened.

PHP programs can translate utf text to entitized text with htmlentities(). Other languages have similar functions. It's clear that the software you used to put your data into MySQL did that.

That entitized text, once you've retrieved it from MySQL, can be translated back to unicode by html_decode().

How can you figure out what's stored in MySQL? Try this:

 SELECT col, CHARACTER_LENGTH(col), HEX(col)

This will show the value of col presented by your client. It will also show the number of characters in the column and the hex coding of the col. The number of characters in an entitized character is six, whereas the number in the unicode character is one.

这篇关于如何插入多语言字符串数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 05:59