当前位置: 首页>>代码示例>>PHP>>正文


PHP CDbConnection::setActive方法代码示例

本文整理汇总了PHP中CDbConnection::setActive方法的典型用法代码示例。如果您正苦于以下问题:PHP CDbConnection::setActive方法的具体用法?PHP CDbConnection::setActive怎么用?PHP CDbConnection::setActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDbConnection的用法示例。


在下文中一共展示了CDbConnection::setActive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: openConnection

 public function openConnection()
 {
     $dsn = "mysql:host={$this->host};port={$this->port};";
     $this->db = new CDbConnection($dsn);
     $this->db->setAttribute(PDO::ATTR_TIMEOUT, $this->connectionTimeout);
     $this->db->setActive(true);
 }
开发者ID:jerrylsxu,项目名称:yii-sphinx,代码行数:7,代码来源:EDbSphinxConnection.php

示例2: openConnection

 /**
  * Open Sphinx persistent connection.
  *
  * @throws ESphinxException if client is already connected.
  * @throws ESphinxException if client has connection error.
  * @link http://sphinxsearch.com/docs/current.html#api-func-open
  */
 public function openConnection()
 {
     $dsn = "mysql:host={$this->server};port={$this->port};";
     $this->db = new ESphinxQlDbConnection($dsn);
     $this->db->setAttribute(PDO::ATTR_TIMEOUT, $this->connectionTimeout);
     $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
     $this->db->setActive(true);
 }
开发者ID:sergebezborodov,项目名称:sphinx-yii,代码行数:15,代码来源:ESphinxMysqlConnection.php

示例3: fork

 public function fork()
 {
     $this->b2b_DbConnection->setActive(false);
     $this->oneC_DbConnection->setActive(false);
     $pid = pcntl_fork();
     $this->b2b_DbConnection->setActive(true);
     $this->oneC_DbConnection->setActive(true);
     return $pid;
 }
开发者ID:xamin123,项目名称:code-example,代码行数:9,代码来源:ForkCreator.php

示例4: setActive

 /**
  * 打开或关闭数据库连接
  *
  * @param boolean $value whether to open or close DB connection
  * @throws CException if connection fails
  */
 public function setActive($value)
 {
     if ($value != $this->getActive() && $value) {
         $this->setAttribute(PDO::ATTR_TIMEOUT, $this->timeout);
     }
     parent::setActive($value);
 }
开发者ID:wuhailin,项目名称:composer,代码行数:13,代码来源:MDbConnection.php

示例5: __construct

 /**
  * Constructor.
  * @param CDbConnection $conn database connection.
  */
 public function __construct($conn)
 {
     $conn->setActive(true);
     $this->_connection = $conn;
     foreach ($conn->schemaCachingExclude as $name) {
         $this->_cacheExclude[$name] = true;
     }
 }
开发者ID:Jride,项目名称:accounting-thaiconnections,代码行数:12,代码来源:CDbSchema.php

示例6: setupDB

 public function setupDB()
 {
     $dump_file = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'db.sql';
     if (!file_exists($dump_file)) {
         return array('error' => 'Dump file was not found');
     }
     $connection = new CDbConnection('mysql:host=' . $this->host . ';port=' . $this->port, $this->user, $this->password);
     $connection->setActive(true);
     $sql = "DROP DATABASE IF EXISTS `{$this->dbname}`; CREATE DATABASE `{$this->dbname}` CHARACTER SET utf8 COLLATE utf8_general_ci;";
     $connection->createCommand($sql)->query();
     $connection->setActive(false);
     $connection = null;
     $connection = new CDbConnection('mysql:host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname, $this->user, $this->password);
     $sql = file_get_contents($dump_file);
     $connection->createCommand($sql)->query();
     $this->saveDBInstallStatusConfig(1);
     return array('ok' => 1);
 }
开发者ID:anton-itscript,项目名称:WM-Web,代码行数:18,代码来源:InstallConfig.php

示例7: install

 public function install()
 {
     # Does the application need installing? Check if database exists, and can connect
     try {
         # Required fields
         $required = array("db-host", "db-name", "db-username", "db-password", "table-prefix");
         # Did all the required fields get passed in?
         if (count(array_intersect($required, array_keys($_REQUEST))) != count($required)) {
             throw new Exception("Not all required fields were submitted.");
         }
         # Verify the required unempty fields
         foreach ($required as $field) {
             # Skip the fields that can be empty
             if ($field == "table-prefix" or $field == "db-password") {
                 continue;
             }
             # Check if empty, throw error if they are.
             if (empty($_REQUEST[$field])) {
                 throw new Exception("Field <i>" . lookupfieldname($field) . "</i> cannot be empty.");
             }
         }
         # Try connecting to the database with the passed in credentials
         try {
             # Setup connection details
             $dsn = 'mysql:host=' . $_REQUEST["db-host"] . ';dbname=' . $_REQUEST["db-name"];
             $username = $_REQUEST["db-username"];
             $password = $_REQUEST["db-password"];
             $prefix = $_REQUEST["table-prefix"];
             # Make the connection
             $conn = new CDbConnection($dsn, $username, $password);
             $conn->active = true;
             $conn->setActive(true);
         } catch (Exception $e) {
             throw new Exception("Could not connect to database. Make sure you have created the database first. Details: " . $e->getMessage());
         }
         # Setup the database params for saving in the extended configuration
         $db_params = array('components' => array('db' => array('connectionString' => $dsn, 'emulatePrepare' => true, 'username' => $username, 'password' => $password, 'charset' => 'utf8', 'tablePrefix' => $prefix)), 'params' => array('LOCALAPP_SERVER' => $_SERVER["HTTP_HOST"]));
         # Make sure to only overwrite if explicitly asked to
         $config_ext = Yii::app()->basePath . "\\config\\main-ext.php";
         if (is_file($config_ext)) {
             throw new Exception("Database configuration already exists. Delete this configuration in order to install this application.");
         }
         # Open up the file and write the new configuration.
         $handle = fopen($config_ext, "w");
         fwrite($handle, "<?php return ");
         fwrite($handle, var_export($db_params, true));
         fwrite($handle, "; ?>");
         fclose($handle);
         # Make read-only
         chmod($config_ext, 060);
     } catch (Exception $e) {
         $this->set_error($e->getMessage());
         return false;
     }
     # If we made it to here, installation is a success!
     return true;
 }
开发者ID:jbrauchler,项目名称:directory,代码行数:57,代码来源:System.php

示例8: validateConnection

 /**
  * Validator for connection to MySQL
  * @return bool     Whether or not we could connect to MySQL
  */
 public function validateConnection()
 {
     // Make sure all fields are provided
     if ($this->validate()) {
         // Just turning the connection on and off. A CDbException will be thrown if something goes wrong
         try {
             $connection = new CDbConnection("mysql:host={$this->host};dbname={$this->dbname}", $this->username, $this->password);
             $connection->setActive(true);
             $connection->setActive(false);
             $this->dsn = $connection->connectionString;
             return true;
         } catch (Exception $e) {
             // Add errors to all fields for the visual indicator
             $this->addError('username', '');
             $this->addError('password', '');
             $this->addError('dbname', '');
             $this->addError('host', '');
             $this->addError('dsn', Yii::t('Install.main', 'Unable to connect to database using the provided credentials.'));
             return false;
         }
     }
     $this->addError('dsn', Yii::t('Install.main', 'Unable to connect to database using the provided credentials.'));
     return false;
 }
开发者ID:fandikurnia,项目名称:CiiMS,代码行数:28,代码来源:DatabaseForm.php

示例9: checkUser

 public function checkUser()
 {
     if ($this->hasErrors('db_exp_sql_host') || $this->hasErrors('db_exp_sql_dbname') || $this->hasErrors('db_exp_sql_login') || $this->hasErrors('db_exp_sql_password') || $this->hasErrors('db_exp_sql_port')) {
         return false;
     }
     try {
         $connection = new CDbConnection('mysql:host=' . $this->db_exp_sql_host, $this->db_exp_sql_login, $this->db_exp_sql_password);
         $res = $connection->setActive(true);
         $sql = "CREATE DATABASE IF NOT EXISTS `{$this->db_exp_sql_dbname}` CHARACTER SET UTF8";
         $res = $connection->createCommand($sql)->query();
     } catch (CDbException $e) {
         $this->addError('db_exp_sql_login', $e->getMessage());
         return false;
     }
     return true;
 }
开发者ID:anton-itscript,项目名称:WM,代码行数:16,代码来源:Settings.php

示例10: setActive

 public function setActive($value)
 {
     if ($value && $this->autoReconnect) {
         $lifetime = time() - $this->_lastActive;
         if ($lifetime > intval($this->autoReconnect)) {
             try {
                 if ($this->getActive()) {
                     @$this->getPdoInstance()->query('SELECT 1');
                 }
             } catch (Exception $e) {
                 Yii::trace($e->getMessage() . " Last connection's lifetime: {$lifetime}, trying to close and reconnect... ", 'components.DbConnection.setActive');
                 parent::setActive(false);
             }
         }
     }
     parent::setActive($value);
     $this->_lastActive = time();
 }
开发者ID:Sywooch,项目名称:olx-rooms-parser,代码行数:18,代码来源:DbConnection.php

示例11: getDbConnection

 /**
  * This is our overloaded getDbConnection, allowing us to tell yii what our db connection is
  * without it having to go through
  */
 public function getDbConnection()
 {
     $connection = new CDbConnection("mysql:host={$this->dsn['host']};dbname={$this->dsn['dbname']}", $this->dsn['username'], $this->dsn['password']);
     $connection->setActive(true);
     return $connection;
 }
开发者ID:xl602,项目名称:CiiMS,代码行数:10,代码来源:CiiMigrateCommand.php

示例12: checkUser

 public function checkUser()
 {
     if ($this->hasErrors('host') || $this->hasErrors('user') || $this->hasErrors('password') || $this->hasErrors('port')) {
         return false;
     }
     try {
         $connection = new CDbConnection('mysql:host=' . $this->host, $this->user, $this->password);
         $connection->setActive(true);
         $sql = "DROP DATABASE IF EXISTS `{$this->dbname}`;";
         $connection->createCommand($sql)->query();
         $sql = "CREATE DATABASE `{$this->dbname}` CHARACTER SET utf8 COLLATE utf8_general_ci;";
         $connection->createCommand($sql)->query();
     } catch (CDbException $e) {
         $this->addError('user', $e->getMessage());
         return false;
     }
     return true;
 }
开发者ID:anton-itscript,项目名称:WM-Web,代码行数:18,代码来源:AdminConfig.php

示例13: foreach

    }
    foreach ($fieldmap as $k => $v) {
        $value = addslashes($_POST[$k]);
        fwrite($fh, "define('{$v[0]}', \"{$value}\");\n");
    }
    fwrite($fh, "define('DB_VERSION', " . DB_VERSION . ");\n");
    fclose($fh);
    header('location: setup.php?a=config');
    return;
}
if (field_value('yii', false) && file_exists($yii = field_value('yii', false))) {
    require_once $yii;
    try {
        $db = new CDbConnection(field_value('dsn', false), field_value('user', false), field_value('password', false));
        $db->tablePrefix = field_value('prefix');
        $db->setActive(true);
        $db_ok = true;
        $curr_db_ver = filemtime(dirname(__FILE__) . '/protected/data/CurrentDbScheme.php');
        $db_new = DB_VERSION >= $curr_db_ver;
    } catch (CException $e) {
        $db_ok = false;
        $db_new = false;
        $err_msg = $e->getMessage();
    }
} else {
    $err_msg = 'Path to yii ("' . field_value('yii') . '") not found';
}
if (isset($_GET['a'])) {
    $page_act = $_GET['a'];
} else {
    $page_act = 'config';
开发者ID:eneelkant,项目名称:oprecx-project,代码行数:31,代码来源:setup.php

示例14: save

 /**
  * This method will save the admin user into the database,
  */
 public function save()
 {
     if (!$this->validateForm()) {
         return false;
     }
     try {
         // Store some data in session temporarily
         Yii::app()->session['encryptionKey'] = $this->encryptionKey;
         Yii::app()->session['siteName'] = $this->siteName;
         Yii::app()->session['primaryEmail'] = $this->email;
         // Try to save the record into the database
         $connection = new CDbConnection(Yii::app()->session['dsn']['dsn'], Yii::app()->session['dsn']['username'], Yii::app()->session['dsn']['password']);
         $connection->setActive(true);
         $connection->createCommand('INSERT INTO users (id, email, password, firstName, lastName, displayName, user_role, status, created, updated) VALUES (1, :email, :password, :firstName, :lastName, :displayName, 9, 1, UTC_TIMESTAMP(), UTC_TIMESTAMP())')->bindParam(':email', $this->email)->bindParam(':password', $this->encryptedPassword)->bindParam(':firstName', $this->firstName)->bindParam(':lastName', $this->lastName)->bindParam(':displayName', $this->displayName)->execute();
         return true;
     } catch (CDbException $e) {
         $this->addError('password', Yii::t('Install.main', 'There was an error saving your details to the database.'));
         return false;
     }
     return false;
 }
开发者ID:fandikurnia,项目名称:CiiMS,代码行数:24,代码来源:UserForm.php

示例15: initDbConnection

 /**
  * Init connection with backup database
  */
 private function initDbConnection()
 {
     It::debug("try to init DB connection (0)", 'backup_database');
     try {
         It::debug("try to init DB connection (1)", 'backup_database');
         // check if (remote) host is reachable
         $fp = @fsockopen($this->settings->db_exp_sql_host, $this->settings->db_exp_sql_port);
         if ($fp === false) {
             throw new Exception("Host " . $this->settings->db_exp_sql_host . ':' . $this->settings->db_exp_sql_port . ' is unreachable');
         }
         // create connection with database
         $dsn = 'mysql:host=' . $this->settings->db_exp_sql_host . ';port=' . $this->settings->db_exp_sql_port . ';dbname=' . $this->settings->db_exp_sql_dbname;
         $connection = new CDbConnection($dsn, $this->settings->db_exp_sql_login, $this->settings->db_exp_sql_password);
         It::debug("try to init DB connection (2)", 'backup_database');
         try {
             It::debug("try to init DB connection (3)", 'backup_database');
             $res = $connection->setActive(true);
             It::debug("try to init DB connection (4)", 'backup_database');
             $this->db_conn = $connection;
             It::debug("try to init DB connection (5)", 'backup_database');
         } catch (PDOException $e) {
             It::debug("try to init DB connection (6)", 'backup_database');
             throw new Exception($e->getMessage());
         }
         It::debug("try to init DB connection (7)", 'backup_database');
     } catch (CDbException $e) {
         It::debug("try to init DB connection (8)", 'backup_database');
         throw new Exception($e->getMessage());
     }
     It::debug("try to init DB connection (DONE)", 'backup_database');
 }
开发者ID:anton-itscript,项目名称:WM-Web,代码行数:34,代码来源:BackupOldData.php


注:本文中的CDbConnection::setActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。