Re: [PHP-I18N] PHP 6: Mysql with iso-8859-1 chars outputting utf-8: "Could not convert binary string to Unicode string"

[email protected] (Andrei Zmievski) Tue, 1 May 2007 17:35:52 -0700
Newsgroups php.i18n
Message-ID <[email protected]>
Georg,

Can you look into this?

-Andrei


On Apr 28, 2007, at 12:20 PM, Rangel Reale wrote:

> Hello!
>
> I have a MySQL database where all tables are in the latin1  
> character set, with accented (Portuguese) characters.
>
> In my php.ini I have
>
> ;;;;;;;;;;;;;;;;;;;;
> ; 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
>
> because all my files and data in mysql server are in iso-8859-1.
>
>
> When connecting to mysql I issue:
>
>   mysql_query('set names latin1', $this->mysql_link);
>
> 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.
>
>
> If I changed the set names query to:
>
>   mysql_query('set names utf8', $this->mysql_link);
>
> it works, but I would like to keep compatibility with PHP 5, and  
> for my application it requires set names to be latin1. Also, my  
> databases are not created with the "utf8" option.
>
> As I understood PHP 6's unicode support, all string characters  
> (including mysql result values) are converted from  
> unicode.runtime_encoding to unicode (utf-16), but looks like it is  
> trying to convert from ASCII, which does not have all the accented  
> characters. Am I assuming right? How to make mysql_fetch_assoc  
> assume field values are in iso-8859-1 instead of ASCII?
>
> Thanks,
> Rangel Reale