Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id B2975632CD3 for ; Thu, 3 Dec 2009 05:42:01 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 71746-04 for ; Thu, 3 Dec 2009 09:41:53 +0000 (UTC) X-Greylist: delayed 00:06:17.608742 by SQLgrey-1.7.6 Received: from mail.morphoss.com (hoppy.mcmillan.net.nz [202.78.240.82]) by mail.postgresql.org (Postfix) with ESMTP id 3F3F3632AC3 for ; Thu, 3 Dec 2009 05:41:53 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.morphoss.com (Postfix) with ESMTP id 1E3EE2341D; Thu, 3 Dec 2009 22:35:31 +1300 (NZDT) X-Virus-Scanned: Debian amavisd-new at mail.morphoss.com Received: from mail.morphoss.com ([127.0.0.1]) by localhost (hoppy.mcmillan.net.nz [127.0.0.1]) (amavisd-new, port 10024) with LMTP id v+RqM66Ap914; Thu, 3 Dec 2009 22:35:16 +1300 (NZDT) Received: from [192.168.55.20] (home.mcmillan.net.nz [202.160.48.75]) (Authenticated sender: andrew@mail.morphoss.com) by mail.morphoss.com (Postfix) with ESMTPSA id D6E0E2341C; Thu, 3 Dec 2009 22:35:15 +1300 (NZDT) Subject: Re: Problem with utf8 encoding From: Andrew McMillan To: Jorge Miranda =?ISO-8859-1?Q?Casta=F1eda?= Cc: pgsql-php@postgresql.org In-Reply-To: <64de42ef0912022300kb4f989fgf34e98bf5d2a838f@mail.gmail.com> (sfid-20091203_200130_562690_BB9F7DF9) References: <64de42ef0912022300kb4f989fgf34e98bf5d2a838f@mail.gmail.com> (sfid-20091203_200130_562690_BB9F7DF9) Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-2hEk/LQgK/pN+/xdpjSV" Date: Thu, 03 Dec 2009 22:35:14 +1300 Message-ID: <1259832914.8024.823.camel@happy.home.mcmillan.net.nz> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/2 X-Sequence-Number: 4097 --=-2hEk/LQgK/pN+/xdpjSV Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 2009-12-03 at 02:00 -0500, Jorge Miranda Casta=C3=B1eda wrote: > Hello everyone! >=20 >=20 > I'm working in a project using postgres, propel, and php. >=20 >=20 > My development environment is: > SO: Windows vista Business SP2 > Postgres: Postgres v8.4 > Propel: Propel generator/runtime v1.4 > PHP: PHP v5.3 >=20 >=20 > Currently I'm struggling with a problem caused by the encoding. > Everytime I try to insert a row into the table CURRENCY, which has ID, > DESC, and SYMBOL as its columns, I get the following error: > Unable to execute INSERT statement. [wrapped: SQLSTATE[22021]: > Character not in repertoire: 7 ERROR: invalid byte sequence for > encoding "UTF8": 0x80 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".] >=20 >=20 > I've created the database using this sentence: > CREATE DATABASE sbs > WITH OWNER =3D sbsadmin > ENCODING =3D 'UTF8' > LC_COLLATE =3D 'Spanish_Peru.1252' > LC_CTYPE =3D 'Spanish_Peru.1252' > CONNECTION LIMIT =3D -1; Hola Jorge, I suspect it's the LC_COLLATE and LC_CTYPE that you have there. I don't *know* this, but they *look* like they are some weird sort of collation/ctype based on the misguided Windows-1252 encoding. Sadly, Windows provides data in this encoding into web forms where the accept charset is supposedly only ISO-8859. In Windows-1252 the Euro currency symbol is somewhere in the 0x80 - 0x9f range - possibly it is 0x80, in fact. I think you would be better to use a consistent locale like es_PE.UTF-8 though if your data is 1252 encoded then you might need to iconv it first. If you have data which is a mix of ISO-8859-1, Windows-1252 and UTF-8 then I can point you at a wee bit of PHP code I wrote which will look at each character in a string and only iconv from 8859/1252 -> UTF-8 if it is a high-bit byte which is not part of a valid UTF-8 character already. The code is here: http://repo.or.cz/w/awl.git/blob/HEAD:/inc/AWLUtilities.php You need both of the last two functions - call the first one during initialisation, and use the second one to clean the strings. Cheers, Andrew McMillan. ------------------------------------------------------------------------ andrew (AT) morphoss (DOT) com +64(272)DEBIAN You will feel hungry again in another hour. ------------------------------------------------------------------------ --=-2hEk/LQgK/pN+/xdpjSV Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEABECAAYFAksXhk4ACgkQjJA0f48GgBLfyACeM0PFPFa4QRs74qOkAz6FmWer G4YAn0CIGkuqFZv/08vf6Q3BWSFeukcS =gEOs -----END PGP SIGNATURE----- --=-2hEk/LQgK/pN+/xdpjSV--