Re: How to specify Charset with PDO/MySQL
Christian Wittwer schrieb:
> Ok, "set names utf8" solved my problem, but I have to pass this option
> everytime I query the database?
> I cannot use "default-character-set", because other php-apps on this
> server still use latin1.
> Any ideas?
You can extend Zend_Db_Adapter_Pdo_Mysql.
My solution looks like this:
class Fx_Db_Adapter_PdoMysql extends Zend_Db_Adapter_Pdo_Mysql {
protected function _connect() {
if ($this->_connection)
return;
parent::_connect();
// please do not touch names if I don't tell you to do so
$this->_connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
$this->query('SET NAMES utf8');
}
}
If you don't want to name your class Zend_Db_Adapter_Pdo_...
or Zend_Db_Adapter_..., because it's not a class provided by Zend, you
can't use Zend_Db::factory(). Instead you have to instantiate your
adapter, i.e.: $db = new Fx_Db_Adapter_PdoMysql($config);
Gunar