{"id":326,"date":"2014-07-30T09:50:25","date_gmt":"2014-07-30T06:50:25","guid":{"rendered":"http:\/\/mednis.info\/wp\/?p=326"},"modified":"2014-07-30T09:52:47","modified_gmt":"2014-07-30T06:52:47","slug":"postgresql-eesterror-invalid-byte-sequence-for-encoding-utf8-0xff","status":"publish","type":"post","link":"http:\/\/mednis.info\/wp\/?p=326","title":{"rendered":"Postgresql EESTERROR invalid byte sequence for encoding &#8220;UTF8&#8221;: 0xff"},"content":{"rendered":"<p>After Postgres update one of our php web gallery stopped working. Uploading of a photo ended with the following error: <code>invalid byte sequence for encoding \"UTF8\": 0xff<\/code><\/p>\n<p>For years we have allways put an &#8216;E&#8217; before escaped image data in our INSERT queries.<br \/>\n<code>pg_query(\"INSERT INTO gallery (name, data) VALUES ('My photo', E'$escaped_image')\");<\/code><\/p>\n<p>I found the solution in <a target=\"_blank\" href=\"http:\/\/php.net\/manual\/en\/function.pg-escape-bytea.php\" title=\"php.net\">http:\/\/php.net\/manual\/en\/function.pg-escape-bytea.php<\/a><\/p>\n<pre>\r\n\/\/ Escape image data\r\n$escaped = pg_escape_bytea($data);\r\n\r\n\/\/ The wrong code, which stopped working after Postgres update\r\npg_query(\"INSERT INTO gallery (name, data) VALUES ('Pine trees', E'$escaped')\");\r\n\r\n\/\/ The right code\r\npg_query(\"INSERT INTO gallery (name, data) VALUES ('Pine trees', '$escaped')\");\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>After Postgres update one of our php web gallery stopped working. Uploading of a photo ended with the following error: invalid byte sequence for encoding &#8220;UTF8&#8221;: 0xff For years we have allways put an &#8216;E&#8217; before escaped image data in our INSERT queries. pg_query(&#8220;INSERT INTO gallery (name, data) VALUES (&#8216;My photo&#8217;, E&#8217;$escaped_image&#8217;)&#8221;); I found the &hellip; <a href=\"http:\/\/mednis.info\/wp\/?p=326\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Postgresql EESTERROR invalid byte sequence for encoding &#8220;UTF8&#8221;: 0xff<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":327,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,28,6],"tags":[],"_links":{"self":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/326"}],"collection":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326"}],"version-history":[{"count":4,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions"}],"predecessor-version":[{"id":331,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions\/331"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/media\/327"}],"wp:attachment":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}