views:

911

answers:

1

Hope here are some with more knowledge about Zend Framework than me, I've been trying to search for the answer but I'm not able to fin anything anywhere.

Problem:

When adding the content of a Zend_Form to the database with the use of Zend_Db the characters æ ø å is replaced by øæå

System

  • WampServer 2.0i
    • Apache 2.2.11
    • MySQL 5.1.36
    • PHP 5.3.0
  • Zend Framework 1.10.0

Modifications done to make it work (which it does not)

application.ini

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "//Brukernavn//"
resources.db.params.password = "//Passord//"
resources.db.params.dbname = "//Database//"
resources.db.params.charset = "utf8"
resources.db.params.driver_options.1002 = "SET NAMES utf8"
resources.db.isDefaultTableAdapter = true

To all forms I've added

->setAttrib('accept-charset', 'utf-8');

And in Bootstrap.php I've placed the following code:

$view->setEncoding('UTF-8');
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');

The database is set to utf8_general_ci

Anyone have a tip on how to get it to work?

Soulution:

It's a bug in PHP 5.3.0 and 5.3.1 ( http://bugs.php.net/bug.php?id=47224 ) so I choose to downgrade to 5.2.11, and all worked like a charm.

Thanks to Pekka and Greg K for pointing me in the right direction.

A: 

Listening to your description, the data departs from the form as UTF-8. Could it be that your database tables themselves are still latin1?

Pekka
I believe he said the database is set to `utf8_general_ci`
Anthony Forloney
Oh yeah, overread that. Still, the tables and their columns need to be utf-8 too (just converting the db isn't enough). If he confirms the tables and columns are UTF-8, I'll delete this answer.
Pekka
Thanks for your answer.Actually I had forgotten to convert the fields themself, but no change in behavior after doing so.
Christian Frøystad
Just a hack, can you try manually running `"SET NAMES utf8"` as a query before you insert the data? Then you'd at least know that the connection is the problem.
Pekka
So when you connect to your MySQL database and type `\s` you see: Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 (assuming `SET NAMES utf8` was issued)?
Greg K
Running "SET NAMES utf8" did the tric.
Christian Frøystad
All right! Then something's wrong with the database parameters. I don't know enough about Zend to know how to fix them. Anyone?
Pekka
Thanks for your help.You got me on the right trac, it's a bug in PHP 5.3.0 and 5.3.1http://bugs.php.net/bug.php?id=47224Thanks again.
Christian Frøystad
@Christian Frøystad: You're welcome, and thanks for the link! That is very good to know.
Pekka