开发者

ZendFramework cuts strings from first non a-z char when inserting to mysql

When I insert some data with Zend_Form to database with non a-z characters like chrząszcz it cuts me this string and in database I have saved only chrz.

Everyting in MySql is set as utf8_general_ci, when connecting with MySql I call SET CHARACTER SET 'utf8', files are also UTF-8.

I have no idea what to do with that.

I wrote also standalone script and it inserts and reads me that string correct. ZendFramework reads it also correct. The problem is only with inserting.

Do anyone know how to fix it ?

UPDATE:

If I insert data w开发者_高级运维ith:

$db->query("INSERT INTO unit SET name = 'chrząszcz'");

in ZendFramework it works. Problem is with inserting that way:

$unitTable = new Model_Unit_Table();
$unit = $unitTable->createRow();
$unit->setFromArray($form->getValues());
$unit->save();

UPDATE 2:

Problem is with using Zend_Filter_StringToLower - it modifies string chrząszcz into chrz�szcz.

How to get this filterto work correct ?


Responding to your comment:

No. var_dump of $form->getValue() gives chrz�szcz. When var_dump a $_POST superglobal it gives correct chrząszcz.

Does this work?

$testArray = array('name' => 'chrząszcz');

$unitTable = new Model_Unit_Table();
$unit = $unitTable->createRow();
$unit->setFromArray($testArray);
$unit->save();

If yes, your problem may be more Zend_Form related.

Edit:

Your filter needs to use mb_strtolower() instead of strtolower().

Edit2:

Try this:

$filter = new Zend_Filter_StringToLower();
$filter->setEncoding('UTF-8');


I'm pretty sure this is an encoding problem. Strings dropping off at the point of the first non-standard (i.e. above the ASCII character set) character is most often caused by inserting UTF-8 data in a non-UTF8 context so my first suspicion would be that the encoding of the database connection is not properly set.

  • Can you try $db->query("SET NAMES utf8"); before calling the insertion commands?
  • Is the connection Zend_form uses definitely $db?
  • Are you 100% sure the page your form is in is UTF-8 encoded?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜