简体   繁体   English

数据库未正确存储希腊字符

[英]Database not storing the Greek Characters correctly

Good afternoon one and all, 大家下午好,

I've recently deployed a website on a remote server, and using the same mySQL creation script, created a database. 我最近在远程服务器上部署了一个网站,并使用相同的mySQL创建脚本创建了一个数据库。 Two of the fields need to display Greek Characters, and so their collation is set to greek_general_ci. 其中两个字段需要显示希腊字符,因此它们的排序规则设置为greek_general_ci。 This works fine on my local dev machine (which is the same as the set up on the server, probably a few security settings are different.) However... 这在我的本地开发机上工作正常(与服务器上的设置相同,可能一些安全设置有所不同。)但是...

I've gone to add some stuff to the data base, and all I'm getting in the data base is ????? 我已经向数据库中添加了一些东西,而我在数据库中得到的只是?????? instead of the greek character Unicode codes that I get on my local machine. 而不是我在本地计算机上获得的希腊字符Unicode代码。

I've checked that the server has the collations on, and the correct character sets. 我检查了服务器上的排序规则以及正确的字符集。 And I've googled for the answer, but alas I've had no success. 我已经用谷歌搜索了答案,但是可惜我没有成功。 I was wondering if it was something I could fix, or should I contact the server admin for them to have a look at it? 我想知道是否可以解决此问题,还是应该联系服务器管理员让他们看看? As I don't want to mess around with the server settings, as there's a live website running off the same data base engine. 我不想弄乱服务器设置,因为有一个实时网站运行在相同的数据库引擎上。

Many thanks in advance. 提前谢谢了。

I've been asked to post the code here, so this is the code as it stands. 我被要求在这里发布代码,所以这就是现在的代码。

AddWord.html I've only added the form, as that's all that needs to be seen. AddWord.html我只添加了表单,这就是所有需要查看的内容。

<form name="addwrd" action="addWord.php" method="post">
                        <label for="greek_word">Greek Word</label>
                        <input type="text" onkeyup="trans(this.id)" id="greek_word" name="GreekWord" size=30><br><br>                        
                        <label for="greek_definition">Greek Definition</label>  
                        <input type="text" onkeyup="trans(this.id)" id="greek_definition" name="GreekDefinition" size=30><br><br>
                        <label for="EnglishWord">English Word</label>
                        <input type="text" name="EnglishWord" size=30><br><br>
                        <label for="EnglishDefinition">English Word</label>
                        <input type="text" name="EnglishDefinition" size=30><br><br>
                        <label for="chapter">Chapter</label>
                        <input type="text" name="chapter" size=20><br><br>
                        <label for="section">Section</label>
                        <input type="text" name="section" size=20><br><br>
                        <label for="hint">Hint</label>
                        <input type="text" name="hint" size=50><br><br>
                        <input type="submit" name="addword" value="Submit">
                    </form>

AddWord.php AddWord.php

include_once( 'admin_dataHandler.php' );

$dataHandler = new DataConnection();

/** 
 * The variables we're getting back from the HTML form we've just filled
 * in.
 */
$greekWord = $_POST['GreekWord'];
$greekDef = $_POST['GreekDefinition'];
$englishWord = $_POST['EnglishWord'];
$englishDef = $_POST['EnglishDefinition'];
$chapter = $_POST['chapter'];
$section = $_POST['section'];
$hint = $_POST['hint'];

$dataHandler->addWord($greekWord, $greekDef, $englishWord, $englishDef, $chapter, $section, $hint);
// The header should redirect to the admin index.html page.

And this is the code from the data handler that adds the word to the data base. 这是来自数据处理程序的代码,将单词添加到数据库中。

function addWord($grkWrd, $grkDef, $engWord, $engDef, $chptr, $sects, $hint){
            $sql = "INSERT INTO word (GreekWord, GreekDefinition, EnglishWord, EnglishDefinition, Chapter, Sections,Hint) values (:grkWrd,:grkDef,:engWrd,:engDef,:chptr,:sctn,:hnt)";
            $stmt = $this->dataHandler->prepare( $sql );
            $stmt->bindParam(':grkWrd', $grkWrd , PDO::PARAM_STR, 45);
            $stmt->bindParam(':grkDef', $grkDef , PDO::PARAM_STR, 45);
            $stmt->bindParam(':engWrd', $engWord , PDO::PARAM_STR, 45);
            $stmt->bindParam(':engDef', $engDef , PDO::PARAM_STR, 45);
            $stmt->bindParam(':chptr', $chptr , PDO::PARAM_STR, 45);
            $stmt->bindParam(':sctn', $sects , PDO::PARAM_STR, 45);
            $stmt->bindParam(':hnt', $hint , PDO::PARAM_STR, 45);
            $stmt->execute();
        }

I hope this provides further information, my apologies for not posting the code the first time out. 希望能提供更多信息,对于第一次不发布代码,我深表歉意。

Thanks for taking the time to look at this. 感谢您抽出宝贵的时间查看此内容。

Welshboy Welshboy

I think that all of those Greek characters should be contained within UTF8 and that'd you'd save yourself some grief by setting everything up to use UTF8. 我认为所有这些希腊字符都应包含在UTF8中,并且通过将所有内容都设置为使用UTF8,您可以避免一些麻烦。

You talked about Greek character unicode codes but the greek collation isn't unicode, it's ISO 8859-7 (see Character Sets and Collations That MySQL Supports ) 您讨论了希腊字符unicode代码,但greek归类不是unicode,它是ISO 8859-7 (请参阅MySQL支持的字符集和归类

I wrote an article on character set problems with PHP/MySQL just a few days ago which I think could have some relevant information. 几天前,我写了一篇有关PHP / MySQL的字符集问题的文章,我认为其中可能包含一些相关信息。 How to Avoid Character Encoding Problems in PHP 如何避免PHP中的字符编码问题

I really doubt it's the database that's the problem. 我真的怀疑这是数据库的问题。 You should double check your code, or post it here, because that's by far the most likely culprit. 您应该仔细检查您的代码,或将其发布在这里,因为到目前为止,这是最有可能的罪魁祸首。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM