That's correct... I assumed that the whole application should run on UTF-8.
The best way then would be to issue the "SET NAMES 'utf8'" query on a
connection basis just for the given problem, which would result in:

Zend_Registry::get('db')->query("SET NAMES 'utf8'");
$states = Zend_Registry::get('db')->fetchAll('SELECT state_id AS id, name_en
AS name FROM core_states WHERE country_id = ?',
        $this->_getParam('countryId'));
echo Zend_Json::encode($states);

As soon as the connection is closed (end of script) the setting will have no
effect any more.

Best regards

Stefan

-----Ursprüngliche Nachricht-----
Von: Benjamin Eberlei [mailto:kont...@beberlei.de] 
Gesendet: Samstag, 11. April 2009 11:13
An: fw-general@lists.zend.com
Betreff: Re: AW: [fw-general] Zend JSON umlaut (special chars)

That advice on the Mysql Init Attribute is dangerous. Its not just adding
this 
easily, because if the app is already in production and running on another 
charset you might break it.

On Saturday 11 April 2009 10:52:34 Stefan Gehrig wrote:
> Hi Andrei,
>
>
>
> please make sure that your data is UTF-8 encoded.
>
> Either run your retrieved data through utf8_encode() or make sure that the
> result returned from the database is UTF-8.
>
> When using MySQL (Zend_Db_Adapter_Pdo_Mysql) you can easily do this by
> adding a 'driver_options' key to your database configuration with
>
> 'driver_options' => array(
>
>     PDO::MYSQL_ATTR_INIT_COMMAND => “SET NAMES ‘utf8’”
>
> )
>
>
>
> Best regards
>
>
>
> Stefan
>
>
>
> Von: Andrei Iarus [mailto:poni1...@yahoo.com]
> Gesendet: Samstag, 11. April 2009 00:26
> An: Zend Framework
> Betreff: [fw-general] Zend JSON umlaut (special chars)
>
>
>
>
> Hello there,
>
>
>
> I have a problem with encoding an array retrieved from DB. I use this:
>
>
>
> $states = Zend_Registry::get('db')->fetchAll('SELECT state_id AS id,
> name_en AS name FROM core_states WHERE country_id = ?',
> $this->_getParam('countryId'));
>
> echo Zend_Json::encode($states);
>
>
>
> If the name_en field has an umlaut (from a german state), the encoding
will
> return null. So
>
> [{"id":"124","name":null},{"id":"125",...]
>
> is an example (with only the first element), but when I var_dump the
> encoded var, I get
>
> array(16) {
>   [0]=>
>   array(2) {
>     ["id"]=>
>     string(3) "124"
>     ["name"]=>
>     string(17) "Baden-Württemberg"
>   }
> ...
>
>
>
> I see the last version (1.7.8). Did you encounter the same problem?
>
>
>
> Thank you

-- 
Benjamin Eberlei
http://www.beberlei.de

Reply via email to