/**
  *
  */
 public function init()
 {
     try {
         parent::init();
     } catch (\CDbException $e) {
         Craft::log($e->getMessage(), LogLevel::Error);
         $missingPdo = false;
         // TODO: Multi-db driver check.
         if (!extension_loaded('pdo')) {
             $missingPdo = true;
             $messages[] = Craft::t('Craft requires the PDO extension to operate.');
         }
         if (!extension_loaded('pdo_mysql')) {
             $missingPdo = true;
             $messages[] = Craft::t('Craft requires the PDO_MYSQL driver to operate.');
         }
         if (!$missingPdo) {
             Craft::log($e->getMessage(), LogLevel::Error);
             $messages[] = Craft::t('There is a problem connecting to the database with the credentials supplied in your db config file.');
         }
     } catch (\Exception $e) {
         Craft::log($e->getMessage(), LogLevel::Error);
         $messages[] = Craft::t('There is a problem connecting to the database with the credentials supplied in your db config file.');
     }
     if (!empty($messages)) {
         throw new DbConnectException(Craft::t('Database configuration errors: {errors}', array('errors' => implode(PHP_EOL, $messages))));
     }
     $this->_isDbConnectionValid = true;
     // Now that we've validated the config and connection, set extra db logging if devMode is enabled.
     if (craft()->config->get('devMode')) {
         $this->enableProfiling = true;
         $this->enableParamLogging = true;
     }
 }
 public function testInitialized()
 {
     $db = new CDbConnection();
     $db->autoConnect = false;
     $this->assertFalse($db->isInitialized);
     $db->init();
     $this->assertTrue($db->isInitialized);
 }
Beispiel #3
0
 public function createDbConnection($db_must_exists = true)
 {
     $conn_string = 'mysql:host=' . $this->db_host . ';' . ($db_must_exists ? 'dbname=' . $this->db_name : '');
     $con = new CDbConnection($conn_string, $this->db_login, $this->db_pass);
     $con->initSQLs = array("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
     $con->init();
     return $con;
 }
Beispiel #4
0
 public function testCreateDb()
 {
     $step1 = new Step1();
     $step1->setAttributes($this->data, false);
     $this->assertTrue($step1->createDb());
     $conn_string = 'mysql:host=' . $step1->db_host . ';dbname=' . $step1->db_name;
     $con = new CDbConnection($conn_string, $step1->db_login, $step1->db_pass);
     try {
         $con->init();
     } catch (Exception $e) {
         $this->assert('Db was not created');
     }
     $con->createCommand('DROP DATABASE IF EXISTS ' . $con->quoteTableName($this->data['db_name']))->execute();
 }
 /**
  * 
  * @param string $attribute
  * @param mixed[] $params
  */
 public function setupConnection($attribute, $params)
 {
     if ($this->dbhost === 'localhost') {
         $this->clearErrors('dbhost');
     }
     if (!$this->hasErrors()) {
         $str = $this->dbtype . ':host=' . $this->dbhost . ':' . $this->dbport . ';dbname=' . $this->dbname;
         if ($this->dbtype === 'mysql' || $this->dbtype === 'mysqli') {
             $str .= ';charset=' . $this->dbenco;
         }
         $connection = new CDbConnection($str, $this->dbuser, $this->dbpass);
         $connection->charset = $this->dbenco;
         try {
             $connection->init();
             $this->connection = $connection;
         } catch (CException $e) {
             $this->addError($attribute, Yii::t('dbms.form', 'Impossible to connect to "{cstr}" with given user ({message}).', array('{cstr}' => $connection->connectionString, '{message}' => $e->getMessage())));
         }
     }
     if ($this->connection === null) {
         $this->dbpass = null;
     }
 }
Beispiel #6
0
 public function init()
 {
     $this->setAttribute(PDO::ATTR_TIMEOUT, $this->dbaTimeout);
     parent::init();
 }
Beispiel #7
0
 /**
  * Initializes the component.
  * This method is required by {@link IApplicationComponent} and is invoked by application
  * when the CDbConnection is used as an application component.
  * If you override this method, make sure to call the parent implementation
  * so that the component can be marked as initialized.
  */
 public function init()
 {
     parent::init();
     if ($this->autoConnect) {
         $this->setActive(true);
     }
 }
 public function init()
 {
     parent::init();
 }