Dondariadmin (トーク | 投稿記録) (ページの作成:「== symfony 1.4 + Doctrine 1.2で必ず実行したいクエリーを記述するには == * symfony 1.4(+Doctrine)で作ったアプリで、DBにMySQLを使うと、DB接...」) |
Dondariadmin (トーク | 投稿記録) |
||
79行目: | 79行目: | ||
84 Query SET NAMES 'UTF8' | 84 Query SET NAMES 'UTF8' | ||
84 Query SET time_zone = '+9:00' | 84 Query SET time_zone = '+9:00' | ||
+ | |||
+ | [[Category:PHP]] | ||
+ | [[Category:symfony]] | ||
+ | [[Category:Doctrine]] |
doctrine: class: sfDoctrineDatabase param: dsn: mysql:host=localhost;dbname=hogehogedb username: hogehogeuser password: hogehogepassword timezone: '+9:00'
class myDoctrineConnectionListener extends Doctrine_EventListener { /** * 接続後イベント * * @param Doctrine_Event $event event object * * @return null * @see Doctrine_EventListener::postConnect() */ public function postConnect(Doctrine_Event $event) { $connection = $event->getInvoker(); /* @var $connection Doctrine_Connection */ $time_zone = sfContext::getInstance()->getDatabaseManager()->getDatabase($connection->getName())->getParameter('timezone'); $connection->execute(sprintf("SET time_zone = '%s';", $time_zone)); } }
class ProjectConfiguration extends sfProjectConfiguration { // (setupメソッドは省略) /** * DB接続時の処理 * * @param Doctrine_Connection $connection * * @return null * @see sfDoctrineDatabase::initialize() */ public function configureDoctrineConnectionDoctrine(Doctrine_Connection $connection) { if ($connection->getDriverName() == 'Mysql') { $eventListener = new myDoctrineConnectionListener(); $connection->addListener($eventListener); } } }
120422 16:39:54 84 Connect hogehogeuser@localhost on hogehogedb 84 Query SET NAMES 'UTF8' 84 Query SET time_zone = '+9:00'Tweet