10

I retrieve datas from mysql

This is normally which i have in db

This is normally i have in db

Seçimler, Şirketler ve Siyasi Partiler

it prints

Se�imler, ?irketler ve Siyasi Partiler

I use sql yog and change some preferences in my db

i set Charset to UTF8 and Collation is utf8_turkish_ci

but still retrieve datas like that

Se�imler, ?irketler ve Siyasi Partiler

why? What's the problem ?

snnlankrdsm
  • 1,401
  • 5
  • 19
  • 29
  • possible duplicate of [Converting HTML foreign characters from MySQL tables to utf-8 characters](http://stackoverflow.com/questions/7003242/converting-html-foreign-characters-from-mysql-tables-to-utf-8-characters) – snnlankrdsm Apr 30 '14 at 05:20

4 Answers4

17

this problem sounds like you've missed to specify a character encoding somewhere. to solve this, simply make sure you've set character encoding to utf-8 everywere (it doesn't actually need to be utf-8, just the same everywhere - but if you've messed up something and need to change some places anyway, i'd strongly recommend using utf-8):

  • tell MySQL to use utf-8. to do this, add this to your my.cnf:

    collation_server = utf8_unicode_ci
    character_set_server = utf8
    
  • before interacting with mysql, send this two querys:

    SET NAMES 'utf8';
    CHARSET 'utf8';
    

    or, alternatively, let php do this afteropening the connection:

    mysql_set_charset('utf8', $conn);
    
  • set UTF-8 as the default charset for your database

    CREATE DATABASE `my_db` DEFAULT CHARACTER SET 'utf8';
    
  • do the same for tables:

    CREATE TABLE `my_table` (
      -- ...
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
  • assuming the client is a browser, serve your content as utf-8 and the the correct header:

    header('Content-type: text/html; charset=utf-8');
    

    to be really sure the browser understands, add a meta-tag:

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    
  • and, last but not least, tell the browser to submit forms using utf-8

    <form accept-charset="utf-8" ...>
    
oezi
  • 51,017
  • 10
  • 98
  • 115
3

You need to mention Charset to UTF8 in your selection query too.

SET NAMES 'utf8';
CHARSET 'utf8';
Shaikh Farooque
  • 2,620
  • 1
  • 19
  • 33
1

What made the difference for me was to add these lines:

collation_server = utf8_unicode_ci

character_set_server = utf8

to my.ini file (at the end of the document) I have tried everything else but they all failed until I made this change. It's really been a great help. Thanks oezi.

Community
  • 1
  • 1
0

I added $this->db->exec("SET NAMES 'utf8'"); in connection and added charset utf8 to my procedure parameters

Sample

PROCEDURE `up_users`(IN `lid` INT, IN `lfirstname` VARCHAR(100) CHARSET utf8, IN `llastname` VARCHAR(100) CHARSET utf8, IN `lstatus` VARCHAR(1) CHARSET utf8, IN `lpassword` VARCHAR(255) CHARSET utf8)
Andronicus
  • 25,419
  • 17
  • 47
  • 88