2011-08-12 19 views
0

我有一个UTF-8的问题。我使用框架Codeigniter。对于客户端,我必须 将CSV文件转换为数据库。但是,当我通过查询将数据添加到数据库 是一个问题。有些角色不工作。例如这个词:Eén。当我在PhpMyadmin添加这个词时,它是正确的。UTF-8问题

当我尝试变成Codeigniter查询时,它没有。 我的数据库站在Utf-8上。 Codeigniter配置是utf-8。数据库配置位于utf-8上。

下面是该查询:

$query = "INSERT INTO lds_leerdoel(id,leerdoel,kind_omschrijving,cito,groep_id,OCW,opbouw, 
kerngebied_id,jaar_maand,KVH,craats,refnivo,toelichting,auteur) 
VALUES 
(
'".$this->db->escape_str($id)."', 
'".$leerdoel."', 
'".$this->db->escape_str($kind_omschrijving)."', 
'".$this->db->escape_str($cito)."', 
'".$this->db->escape_str($groep_id)."', 
'".$this->db->escape_str($OCW)."', 
'".$this->db->escape_str($opbouw)."', 
'".$this->db->escape_str($kerngebied_id)."', 
'".$this->db->escape_str($jaar_maand)."', 
'".$this->db->escape_str($KVH)."', 
'".$this->db->escape_str($craats)."', 
'".$this->db->escape_str($refnivo)."', 
'".$this->db->escape_str($toelichting)."', 
'".$this->db->escape_str($auteur)."' 
)"; 

$this->db->query($query); 

的问题是场leerdoel。有人提供解决方案吗?非常感谢!!

问候, 耶勒

+2

为什么我们在'leerdoel'上使用'utf8_decode',如果你想这是UTF-8? – Andris

+0

嗨,那就对了。对不起,我忘了删除那个。但问题依然存在。谢谢你的评论! – JelleP

回答

0

不应该使用国家字符串文字吗? http://dev.mysql.com/doc/refman/5.0/en/charset-national.html

这意味着你可以这样写:

$query = "INSERT INTO lds_leerdoel(id,leerdoel,kind_omschrijving,cito,groep_id,OCW,opbouw, 
kerngebied_id,jaar_maand,KVH,craats,refnivo,toelichting,auteur) 
VALUES 
(
'".$this->db->escape_str($id)."', 
N'".$leerdoel."', 
-- rest of query omitted 
1

你需要插入查询之前运行此查询

"SET NAMES utf8" 
+0

我已经试过了。它不工作。但感谢您的评论! – JelleP

0

尝试将文本转换与iconv()为Unicode:

iconv("ISO-8859-1", "UTF-8", $leerdoel); 

你可能如果你不知道文件使用什么编码,就需要做一点实验。 (我认为ISO-8859-1或ISO-8859-15是最常见的。)

+0

是的,这个作品除了字符 - 。但我改变这个 - 。一个较小的。谢谢! – JelleP

0

尝试添加以下内容到标题

header('Content-Type: text/html; Charset=UTF-8'); 

另外,请检查您的编辑器的编码设置。

0

我也有类似的问题,我解决我的PHP文件的开头添加此:

ini_set('default_charset', 'UTF-8'); 
mb_internal_encoding('UTF-8'); 

另外,很重要的检查,如果你保存在UTF-8格式的PHP文件没有BOM ,我对此感到很头疼。我推荐Notepad++,它显示了当前的文件编码,并允许您在没有BOM的情况下转换为UTF-8(如有必要)。

如果您想要查看我的问题和解决方案,请拨打it is here

希望它能帮助你!