Re: Trying to understand PHP6's unicode support

From: Date: Thu, 03 May 2007 11:29:30 +0000
Subject: Re: Trying to understand PHP6's unicode support
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-29142@lists.php.net to get a copy of this message
> Hello! > > I am trying to understand how PHP6 handling of unicode works, I think I am > missing something. > > My config is: > > ;;;;;;;;;;;;;;;;;;;; > ; Unicode settings ; > ;;;;;;;;;;;;;;;;;;;; > > unicode.semantics = on > unicode.runtime_encoding = iso-8859-1 > unicode.script_encoding = iso-8859-1 > unicode.output_encoding = utf-8 > unicode.from_error_mode = U_INVALID_SUBSTITUTE > unicode.from_error_subst_char = 3f > unicode.fallback_encoding = iso-8859-1 > > I use a mysql database, with iso-8859-1 (Portuguese - latin 1) text, with > accented characters. > > What I was trying to understand was, because unicode.runtime_encoding = > iso-8859-1, I tought that all internal operations were done in this > encoding, and only when outputting (unicode.output_encoding = utf-8) data > would be converted to utf-8. So to me, I did a mysql query with latin1, > data > comes to my variables as iso-8859-1, I use them, and only when I echo'ed > them, they would become utf-8, from a iso-8859-1-to-utf-8-like function. > > But when I do query in any record that have accented characters I get this > warning (using mysql_fetch_assoc): > > ---------- > Could not convert binary string to Unicode string (converter UTF-8 failed > on > bytes (0xE7) at offset 9) > ---------- > > for all accented characters in all fields. > > The strange thing to me, is the mysql_fetch_assoc function give this error > even before I accessed the field values, as I understanded from the above > explanation. > > If I changed the set names query to: > > mysql_query('set names utf8', $this->mysql_link); > > then it works, but I would like to understand how this works, to make my > program the right way from the start. > > Did I misundertood something? I think you are confusing PHP features with MySQL features. By running 'SET NAMES' query you set client, connection and result character sets in MySQL (see http://dev.mysql.com/doc/refman/4.1/en/charset.html). It is not related to PHP. MySQL has internal character set support since 4.1 version. -- Tomas

« previous php.internals (#29142) next »