title: Php code igniter save turkish characters to my sql
body: <p>I am writing a web app using PHP Codeigniter. I receive input that can be in any language and I save it in my DB. </p>
  
  <p>The MYSQL DB collation is set to utf8_unicode_ci. 
  For codeigniter in the database.php I have set this:</p>
  
  <pre><code>$db['default']['char_set'] = 'utf8';
  $db['default']['dbcollat'] = 'utf8_unicode_ci';
  </code></pre>
  
  <p>When I run the following insert on my DB:</p>
  
  <pre><code>insert into user (name,id) values ('John Temirtaş', 2)
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Incorrect string value: '\xC5\x9F' for column 'name' at row 1</p>
  </blockquote>
  
  <p>There is a problem with the s. Its a turkish character. </p>
  
  <p>So far I have tried this while debugging</p>
  
  <pre><code>print_r($name)
  John Temirtaş
  
  print_r("Encoded Name: ".utf8_encode($name))
  Encoded Name: John TemirtaÅ
  
  print_r("Decoded Name".utf8_decode($name)
  Encoded Name: John Temirta?
  
  print_r("Decoded-Encode Name: ".utf8_decode(utf8_encode($name)))
  Decoded-Encode Name: John Temirtaş
  </code></pre>
  
  <p>I have tried saving John TemirtaÅ in the db and it works fine. So I think I might <code>utf8_encode($name)</code> before saving it in the DB and utf8_decode before displaying it. Just doing the latter will NOT work. YOU NEED TO ADD <code>mb_internal_encoding("UTF-8");</code> to the top of your php script.</p>
  
  <p>How do I encode the data properly so that its inserted?</p>
  
  <hr>
  
  <p><strong>THANK YOU EVERYONE FOR YOU HELP HERE IS WHAT WORKED!</strong></p>
  
  <ol>
  <li>Open up MySql work bench. Set the
  character encoding and collation of
  the user table. Charset: utf-8
  Collation: utf8_unicode_ci </li>
  <li>Set the collation of the <strong>name</strong> column
  to <strong>utf8_unicode_ci</strong>. Done. The
  insert should work.</li>
  </ol>
  
  <p>Thank you for all your help.</p>