0

我创建了一个表单,其中包含我想存储在 MySQL 表中的印地语 (UTF-8) 数据。与 UTF 数据对应的列的排序规则值设置为utf_general_ci

我已成功将数据存储在表中,但是当我执行 select-where 查询时,它不会返回数据。这是我的查询:

选择Birthsno, Birth. bookingnumber, Birth. birth_date, Birth. baby_gender, Birth. baby_name, Birth. baby_father_name, Birth. baby_father_address, Birth. baby_mother_name, Birth. birth_place, Birth. place_type, Birth. applicant_name, Birth. applicant_address, Birth. registration_number, Birth. registration_date, Birth. registration_ward, Birth. registration_city_village, Birth. registration_district, Birth. remark, Birth. mother_place_name, Birth. mother_place_type, Birth. mother_place_district, Birth. mother_place_state, Birth. person_religion, Birth. father_education, Birth. mother_education, Birth. father_occupation, Birth. mother_occupation, Birth. mother_age_at_marriage, Birth.mother_age_at_birth, Birth. count_of_mother_child, Birth. birth_by, Birth. birth_method, Birth. mother_weight_at_birth, Birth. pregnancy_duration, Birth. date_of_issuenp。 在births哪里。=“d”和。='e'和。='f'和。=“g”和。= 'हिंदू' AND . ='पुरुष' BirthBirthbaby_nameBirthbaby_father_nameBirthbaby_mother_nameBirthbaby_father_addressBirthperson_religionBirthbaby_gender

数据库的名称是np,表的名称是births 上面的查询打印在日志文件中。我试图在 HeidiSQL(MySQL 的前端)中复制并粘贴相同的查询,但它没有运行。但是,如果我删除以下部分: ** AND Birthperson_religion= 'हिंदू' AND Birth. baby_gender= 'पुरुष'**,查询工作正常。

我该如何解决这个问题?

4

1 回答 1

2

当您的 MySQL 客户端和您的 MySQL 服务器不“谈论”相同的编码时,这看起来像是一种情况。

有 3 个地方需要注意编码。

Web 表单(用户所见)-> 您的 Web 应用程序 (CakePHP) -> 您的数据库服务器 (MySQL)

这三个中的一个没有使用与其他编码相同的编码。所以到时候:

“'हिंदू'”和“'पुरुष'”进入您的数据库,它们将是完全不同的东西,不会在数据库中找到。

因此,请确保在您的 default.ctp 文件中设置了编码:

echo $this->Html->charset();//这将导致页面的UTF-8编码。

查看您网页的源代码(我猜您有一个搜索/过滤表单)。

在顶部,您应该看到:

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

然后查找为您的搜索/过滤表单生成的代码。你应该看到:

<form id="your_form_id" accept-charset="utf-8" method="post" action="/your/action/">

重要的部分是“utf-8”必须出现在那些地方。

接下来,查看您的database.php文件并确保此行:

'encoding' => 'utf8',没有被注释掉!

最后,使用您确定支持 UTF-8(可能是 HeidiSQL)的客户端,查看您的数据表np.births并确保您拥有的数据实际上是有意义的!由于之前的编码差异,它可能会被破坏。

一旦数据在数据库中有意义,您就可以开始了!

如果这对你不起作用,你必须阅读并彻底理解这篇文章。只有这样,您才能找到问题所在并同步编码。(显然你的 PHP 源文件也应该是 UTF-8 编码的......)

于 2014-02-01T10:17:42.547 回答