示例#1
0
 /**
  * Inject
  *
  * 操作によってDBオブジェクトを変更します
  * read操作はdsnをslaveに、DBページャーを利用可能に。
  * その他操作はdsnをdefaultに、トランザクション可能にしExtendedモジュール読み込みます
  *
  * @return void
  */
 public function onInject()
 {
     $app = BEAR::get('app');
     $options['default_table_type'] = 'INNODB';
     if ($this->_config['method'] === 'read') {
         $dsn = $app['App_Db']['dsn']['slave'];
         $config = array('dsn' => $dsn, 'options' => $options);
         $this->_db = BEAR::factory('BEAR_Mdb2', $config);
         $this->_queryConfig = array('db' => $this->_db, 'ro' => $this, 'table' => $this->_table, 'pager' => 0, 'options' => array('accesskey' => true));
     } else {
         $dsn = $app['App_Db']['dsn']['default'];
         $options['use_transactions'] = true;
         $config = array('dsn' => $dsn, 'options' => $options);
         $this->_db = BEAR::factory('BEAR_Mdb2', $config);
         $this->_db->loadModule('Extended');
         $this->_queryConfig = array('db' => $this->_db, 'ro' => $this, 'table' => $this->_table);
     }
 }
示例#2
0
 /**
  * インジェクタ
  *
  * <pre>
  * 操作によってDBオブジェクトを変更します
  *
  * read操作はdsnをslaveに、DBページャーを利用可能に。
  * その他操作はdsnをdefaultに、トランザクション可能にしExtendedモジュール読み込みます
  * </pre>
  */
 public function onInject()
 {
     $app = BEAR::get('app');
     assert(is_string($app['App_Db']['dsn']['default']));
     assert(is_string($app['App_Db']['dsn']['slave']));
     assert(isset($this->_config['method']));
     $options['default_table_type'] = 'INNODB';
     if ($this->_config['method'] === 'read') {
         $dsn = $app['App_Db']['dsn']['slave'];
         $config = array('dsn' => $dsn, 'options' => $options);
         $this->_db = BEAR::factory('BEAR_Mdb2', $config);
         $this->_queryConfig = array('db' => &$this->_db, 'ro' => &$this, 'table' => $this->_table, 'pager' => 0, 'perPage' => 10, 'options' => array('accesskey' => true));
     } else {
         $dsn = $app['App_Db']['dsn']['default'];
         $options['use_transactions'] = true;
         $config = array('dsn' => $dsn, 'options' => $options);
         $this->_db = BEAR::factory('BEAR_Mdb2', $config);
         $this->_db->loadModule('Extended');
         $this->_queryConfig = array('db' => &$this->_db, 'ro' => &$this, 'table' => $this->_table);
     }
     // すべてのフィールド識別子が SQL 文中で自動的にクォート
     $this->_db->setOption('quote_identifier', true);
 }