When your using a persistence layer like Zend_Db or Doctrine, setting the character set is crucial in order for everything to turn out as expected in your database. I've spent too much time trying to sort character encoding issues in the past, so I'm putting it here as a reference.
In Zend_Db, after configuring your database, in order for arabic / persian / non-ascii characters to persist properly, you need to configure the character set:
// setup database $db = Zend_Db::factory($config->db->adapter, $config_values); // for Unicode support $db->query("SET NAMES 'utf8'"); Zend_Db_Table::setDefaultAdapter($db);
In Doctrine, a similar declaration is needed to setup the right character set. These lines would be in the config.php file included in the sample project, or whenever you initialize your Doctrine_Manager:
$connection = Doctrine_Manager::connection(DB_PATH); $connection->setCharset('UTF8');
{ 1 comment… read it below or add one }
Great tip, thanks!