Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- resources.doctrine.dbal.connections.default.parameters.driverOptions.1002 = "SET NAMES 'UTF8'"
- // $options is a simple array to hold your data
- $connectionOptions = array(
- 'driver' => $options['conn']['driv'],
- 'user' => $options['conn']['user'],
- 'password' => $options['conn']['pass'],
- 'dbname' => $options['conn']['dbname'],
- 'host' => $options['conn']['host'],
- 'charset' => 'utf8',
- 'driverOptions' => array(
- 1002 => 'SET NAMES utf8'
- )
- );
- $em = DoctrineORMEntityManager::create($connectionOptions, $config);
- // libraryMyApplicationResourceDoctrine.php
- class My_Application_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
- {
- public function init()
- {
- $options = $this->getOptions();
- $config = new DoctrineORMConfiguration();
- //doctrine autoloader, config and other initializations
- ...
- $connectionOptions = array(
- .... //see above
- );
- $em = DoctrineORMEntityManager::create($connectionOptions, $config);
- $registry = Zend_Registry::getInstance();
- $registry->em = $em;
- return $em;
- }
- }
- resources.doctrine.conn.host = '127.0.0.1'
- resources.doctrine.conn.user = '...'
- resources.doctrine.conn.pass = '...'
- ....
- <?php
- return array(
- 'doctrine' => array(
- 'connection' => array(
- 'orm_default' => array(
- 'driverClass' => 'DoctrineDBALDriverPDOMySqlDriver',
- 'params' => array(
- 'host' => 'localhost',
- 'port' => '3306',
- 'user' => '...',
- 'password' => '...',
- 'dbname' => '...',
- 'driverOptions' => array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
- )
- ),
- )
- )
- )
- );
- resources.entitymanagerfactory.connectionOptions.driverOptions.1002 = "SET NAMES utf8"
- default-character-set=utf8
- resources.doctrine.dbal.connections.default.parameters.driverOptions.charset = "utf8"
- // Create new Doctrine Manager instance
- $doctrineManager = Doctrine_Manager::getInstance();
- // Set charset to UTF8
- $doctrineManager->setAttribute(
- Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET,
- 'utf8'
- );
- resources.doctrine2.connection.driverOptions.1002 = "SET NAMES 'UTF8'"
- protected function _initDoctrineLibrary()
- {
- require_once('Doctrine/Doctrine.php');
- $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine', 'autoload'),'Doctrine');
- $manager = Doctrine_Manager::getInstance();
- $manager->setAttribute(
- Doctrine::ATTR_MODEL_LOADING,
- Doctrine::MODEL_LOADING_CONSERVATIVE
- );
- $config = $this->getOption('doctrine');
- $conn = Doctrine_Manager::connection($config['dsn'],'doctrine');
- $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
- return $conn;
- }
- doctrine.dsn = "mysql://user:password@host/databasename"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement