Thu - Oct 23, 2008 : 06:12 pm
PHP / PGSQL Character Encoding
I've been writing a snippet of code to take a list of rows from a table in an Oracle database, and have been having problems with a pesky error having to do with PostgreSQL's character encoding and PHP's handling of it.
The error I've been receiving is thus:
Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xae 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"
So, after a bit of research and asking in the wonderful people in the UPHPU IRC room, I found the answer.
The PHP function, pg_set_client_encoding() enables me to run the SQL and it inserts everything just fine. Evidently, the Oracle database's character encoding is set to LATIN1. So the following code set things right:
And that is that! Hope that helps someone in need.