Example #1
0
 /**
  * Connects to the specified schema and assigns it to all models which need it.
  *
  * @param	$schema				schema
  * @return	CDbConnection
  */
 protected function connectDb($schema)
 {
     // Assign request
     $this->request = Yii::app()->getRequest();
     // Check parameter
     if (is_null($schema)) {
         $this->db = null;
         return null;
     }
     // Connect to database
     $connectionString = 'mysql:host=' . Yii::app()->user->host . ';port=' . Yii::app()->user->port . ';dbname=' . $schema . '; charset=utf8';
     $this->db = new CDbConnection($connectionString, utf8_decode(Yii::app()->user->name), utf8_decode(Yii::app()->user->password));
     $this->db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES \'utf8\'');
     $this->db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET CHARACTER SET \'utf8\'');
     $this->db->charset = 'utf8';
     $this->db->emulatePrepare = true;
     $this->db->active = true;
     // Schema name is set in connection string
     // $this->db->createCommand('USE ' . $this->db->quoteTableName($schema))->execute();
     // Assign to all models which need it
     ActiveRecord::$db = Routine::$db = Row::$db = Trigger::$db = View::$db = $this->db;
     // Return connection
     return $this->db;
 }
Example #2
0
 /**
  * Setup test databases.
  */
 protected function setUp()
 {
     $this->executeSqlFile('models/ViewTest.sql');
     View::$db = $this->createDbConnection('viewtest');
 }
Example #3
0
 /**
  * Setup test databases.
  */
 protected function setUp()
 {
     $this->executeSqlFile('models/ForeignKeyTest.sql');
     Column::$db = ForeignKey::$db = Index::$db = Routine::$db = Row::$db = Schema::$db = Table::$db = Trigger::$db = View::$db = $this->createDbConnection('tabletest');
 }