title: Postgresql SQLSTATE[22021]: Character not in repertoire: Ö
body: <p>This question was asked many times, but no solution worked for me, I have this piece of code:</p>
  <pre><code>Changes::$change['text'] = $data-&gt;employee-&gt;emp_first_name . &quot;, &quot; . $data-&gt;employee-&gt;emp_last_name . &quot; in Woche &quot; .  $data-&gt;employee-&gt;week . &quot; gelöscht &lt;br&gt;&quot;;
  Changes::$change['user'] = $data-&gt;user-&gt;name;
  $date = date_create();
  $changeLogSql = utf8_encode(&quot;INSERT INTO change_log (date, name, change, affected_table) VALUES (now(), '&quot;. Changes::$change['user'] .&quot;', '&quot;. Changes::$change['text'] .&quot;', '&quot; . Changes::$change['table'] . &quot;')&quot;);
  $fetched[0]['debug'] = $changeLogSql;
  $result = $pdo-&gt;query($changeLogSql);
  </code></pre>
  <p>Without the <code>utf8_encode</code> I get sometimes the error:</p>
  <p><code>Postgresql SQLSTATE[22021]: Character not in repertoire: ERROR:  invalid byte sequence for encoding &quot;UTF8&quot;:</code></p>
  <p>In this <code>Insert</code> the problem is the <code>ö</code> in <code>gelöscht</code>. This could I fix by my own but some name´s also contain the character ö and lead to the same byte sequence error.</p>
  <p>In my test enviroment it works fine, just on the production side the error occurs. Both using potsgresql 9.6.</p>
  <p>Any idea how I can get it working without <code>utf8_encode</code>? With it, it looks like &quot;Ã¶t&quot; in my database.</p>
  <p><a href="https://i.stack.imgur.com/Us4Oz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Us4Oz.png" alt="enter image description here" /></a></p>
  <p>A small addition in the same php file I also insert the same names without any problem in different tables (without encode). The problem only occurs in this statement. All name fields are defined as text or varchar.</p>