Thursday, July 28, 2011

pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe28022

Has anyone been face with this problem while trying some inserts into a postgres  DB with some character.

PHP Warning: pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe28022
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".


Now this is not actually a posgres error but a php issue with html entity encode and decode functionalities. The same effect will happen on a MySQL db since MySQL and PostGre are fairly similar. This can be resolved by setting the character encoding in the php file to that of the database base. Eg for UTF-8 DB set the following in metadata the php file.

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />