Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. resources.doctrine.dbal.connections.default.parameters.driverOptions.1002 = "SET NAMES 'UTF8'"
  2.  
  3. // $options is a simple array to hold your data
  4. $connectionOptions = array(
  5. 'driver' => $options['conn']['driv'],
  6. 'user' => $options['conn']['user'],
  7. 'password' => $options['conn']['pass'],
  8. 'dbname' => $options['conn']['dbname'],
  9. 'host' => $options['conn']['host'],
  10. 'charset' => 'utf8',
  11. 'driverOptions' => array(
  12. 1002 => 'SET NAMES utf8'
  13. )
  14. );
  15.  
  16. $em = DoctrineORMEntityManager::create($connectionOptions, $config);
  17.  
  18. // libraryMyApplicationResourceDoctrine.php
  19. class My_Application_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
  20. {
  21.  
  22. public function init()
  23. {
  24. $options = $this->getOptions();
  25. $config = new DoctrineORMConfiguration();
  26. //doctrine autoloader, config and other initializations
  27. ...
  28. $connectionOptions = array(
  29. .... //see above
  30. );
  31. $em = DoctrineORMEntityManager::create($connectionOptions, $config);
  32. $registry = Zend_Registry::getInstance();
  33. $registry->em = $em;
  34. return $em;
  35. }
  36. }
  37.  
  38. resources.doctrine.conn.host = '127.0.0.1'
  39. resources.doctrine.conn.user = '...'
  40. resources.doctrine.conn.pass = '...'
  41. ....
  42.  
  43. <?php
  44. return array(
  45. 'doctrine' => array(
  46. 'connection' => array(
  47. 'orm_default' => array(
  48. 'driverClass' => 'DoctrineDBALDriverPDOMySqlDriver',
  49. 'params' => array(
  50. 'host' => 'localhost',
  51. 'port' => '3306',
  52. 'user' => '...',
  53. 'password' => '...',
  54. 'dbname' => '...',
  55.  
  56. 'driverOptions' => array(
  57. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  58. )
  59.  
  60. ),
  61.  
  62. )
  63. )
  64. )
  65. );
  66.  
  67. resources.entitymanagerfactory.connectionOptions.driverOptions.1002 = "SET NAMES utf8"
  68.  
  69. default-character-set=utf8
  70.  
  71. resources.doctrine.dbal.connections.default.parameters.driverOptions.charset = "utf8"
  72.  
  73. // Create new Doctrine Manager instance
  74. $doctrineManager = Doctrine_Manager::getInstance();
  75.  
  76. // Set charset to UTF8
  77. $doctrineManager->setAttribute(
  78. Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET,
  79. 'utf8'
  80. );
  81.  
  82. resources.doctrine2.connection.driverOptions.1002 = "SET NAMES 'UTF8'"
  83.  
  84. protected function _initDoctrineLibrary()
  85. {
  86. require_once('Doctrine/Doctrine.php');
  87. $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine', 'autoload'),'Doctrine');
  88.  
  89. $manager = Doctrine_Manager::getInstance();
  90. $manager->setAttribute(
  91. Doctrine::ATTR_MODEL_LOADING,
  92. Doctrine::MODEL_LOADING_CONSERVATIVE
  93. );
  94. $config = $this->getOption('doctrine');
  95. $conn = Doctrine_Manager::connection($config['dsn'],'doctrine');
  96. $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
  97. return $conn;
  98. }
  99.  
  100. doctrine.dsn = "mysql://user:password@host/databasename"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement