简体   繁体   English

字符未正确显示在数据库中

[英]Characters not displayed correctly in database

I am developing my app in codeigniter I got my characters like ī, ū, ā ,š etc . 我正在用codeigniter开发我的应用程序,得到了ī, ū, ā ,š等字符。 When i insert them in database i do utf8_encode('$this->input->post('mypostdata')') . 当我将它们插入数据库时​​,我会执行utf8_encode('$this->input->post('mypostdata')') When i echo them out on page i do utf8_decode($enterie->row('myrow')) , everything is displaying just fine. 当我在页面上回显它们时,我执行utf8_decode($enterie->row('myrow')) ,一切都显示正常。 But when i open database, all those characters are displayed like Ä« or Å¡ etc. I got my database collation set to utf8_general_ci . 但是,当我打开数据库时,所有这些字符都显示为Ä«或Å¡等。我将数据库排序规则设置为utf8_general_ci Codeigniter db config file Codeigniter数据库配置文件

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';

i have checked db charset with SHOW CREATE DATABASE DB_NAME , i got /*! 我已经用SHOW CREATE DATABASE DB_NAME检查了数据库字符集,我得到了/ *! 40100 DEFAULT CHARACTER SET utf8 */ 40100 DEFAULT CHARACTER SET utf8 * /

I searched information and found something about my.cnf file, but my page and database is hosted on ipage.com . 我搜索了信息并找到了有关my.cnf文件的信息,但是我的页面和数据库托管在ipage.com上。

So what are options i should check ? 那么我应该检查哪些选项?

I already faced this issue. 我已经面临这个问题。 You need just one line of code using iconv() function: 使用iconv()函数仅需要一行代码:

Try this: 尝试这个:

$post_data1= $this->input->post('mypostdata'); //data with ī, ū, ā ,š
$post_data= iconv('UTF-8', 'ASCII//TRANSLIT', $post_data1); //now it will become i, u, a etc.

now send $post_data to database. 现在将$post_data发送到数据库。

and it will work. 它会工作。

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

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