You are not logged in.
Pages: 1
Recently i ran in to a problem with my charset when i used the Zend and Doctrine libraries to develop my project. I have build a form with Zend_Form and then I use this code to save the data to the database:
<?php
public function addAction() {
if ($this->getRequest()->isPost()) {
if ($this->frm->isValid($this->_getAllParams())) {
$name = $this->_getParam('name');
$desc = $this->_getParam('description');
$acti = $this->_getParam('active') == 1 ? 1 : 0;
$seas = $this->_getParam('season');
$recepie = new Model_Recepie(null, true);
$recepie->name = $name;
$recepie->description = $desc;
$recepie->season = $seas;
$recepie->active = $acti;
$recepie->save();
} // Form is valid
} //Request is POST
$this->view->frm = $this->frm;
}As you can see, it is quite simple. And when i print it in my view-files it works perfectly.
But, when you really dig in to it and check the database and look at the Recepie-table the swedish characters ÅÄÖ looks like åäö.
I solved this problem by adding two lines of code in my Bootstrap.php
<?php
protected function _initDoctrine() {
/** [...] **/
$conn = Doctrine_Manager::connection ( $doctrineConfig ['dsn'], 'doctrine' );
$conn->setAttribute ( Doctrine::ATTR_USE_NATIVE_ENUM, true );
$conn->setCharset ( 'utf8' );
$conn->setCollate ( 'utf8_unicode_ci' );
return $conn;
}As you can se, it's a pretty simple fix.
Offline
It sounds like your database table is latin1 so you were handling the data as utf8 but storing it as latin1 which would cause a problem when you start reading it again.
Your setcharset and setcollate is a hack which works around this oversight.
Offline
My table is is utf-8
Offline
Pages: 1