本文整理汇总了PHP中CDbConnection::init方法的典型用法代码示例。如果您正苦于以下问题:PHP CDbConnection::init方法的具体用法?PHP CDbConnection::init怎么用?PHP CDbConnection::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDbConnection
的用法示例。
在下文中一共展示了CDbConnection::init方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
*
*/
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;
}
}
示例2: testInitialized
public function testInitialized()
{
$db = new CDbConnection();
$db->autoConnect = false;
$this->assertFalse($db->isInitialized);
$db->init();
$this->assertTrue($db->isInitialized);
}
示例3: createDbConnection
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;
}
示例4: testCreateDb
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();
}
示例5: setupConnection
/**
*
* @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;
}
}
示例6: init
public function init()
{
$this->setAttribute(PDO::ATTR_TIMEOUT, $this->dbaTimeout);
parent::init();
}
示例7: init
/**
* 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);
}
}
示例8: init
public function init()
{
parent::init();
}