On 7/21/07, aldnin <[EMAIL PROTECTED]> wrote:
When I try to send this query (select 'lacarrière' as test;) to a UTF8 
initialized pgsql-database (8.2.4) from PHP 5.2.3 I get this error:

ERROR:  invalid byte sequence for encoding "UTF8": 0xe87265

Short answer: start using utf-8 for just everything, and your problems
will be gone.

Long explanation:
This is usually the case when you get data from a form and put it in
the database, and the two aren't using the same encoding.
I guess your pg connection is using unicode (so the db expects unicode
input), and your html is set to something else. To fix this, you have
two choices:

1-Run utf8_encode() on the input from your forms; or
2-Set all your html pages to use utf-8 encoding.

IMHO, option 2 is the way to go. I've been using utf-8 for everything
for quite some time, and has solved all my problems dealing with
accents, and so on.
You will need:
- All your HTML files encoded to utf-8 (quite easy with iconv, if you
are using Linux);
- Add a "Content-type: text/html; charset=utf-8" to all your pages.
This is easily done using PHP's header() function in a file included
by all your scripts.

This way, the pages will be unicode, any data entered will be posted
as unicode, and you will have no problems sending them to a database
that uses unicode.
Forget the <meta> tag that sets the encoding. It's only used in case
the server doesn't send a Content-type header, which isn't the case
normally. By default, I think at least apache sends the content-type
as iso8859-1.

Bruno Lustosa <[EMAIL PROTECTED]>
ZCE - Zend Certified Engineer - PHP!

Reply via email to