简体   繁体   中英

Characters not displayed correctly in database

I am developing my app in codeigniter I got my characters like ī, ū, ā ,š etc . When i insert them in database i do 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. But when i open database, all those characters are displayed like Ä« or Å¡ etc. I got my database collation set to utf8_general_ci . Codeigniter db config file

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

i have checked db charset with SHOW CREATE DATABASE DB_NAME , i got /*! 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 .

So what are options i should check ?

I already faced this issue. You need just one line of code using iconv() function:

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.

and it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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