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


PHP CDbConnection::setAttribute方法代码示例

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


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

    public function setUp()
    {
        if (self::DB_DSN_PREFIX == 'sqlsrv' && (!extension_loaded('pdo') || !extension_loaded('sqlsrv') || !extension_loaded('pdo_sqlsrv'))) {
            $this->markTestSkipped('PDO and SQLSRV extensions are required.');
        } else {
            if (self::DB_DSN_PREFIX != 'sqlsrv' && (!extension_loaded('pdo') || !extension_loaded('pdo_dblib'))) {
                $this->markTestSkipped('PDO and MSSQL extensions are required.');
            }
        }
        if (self::DB_DSN_PREFIX == 'sqlsrv') {
            $dsn = self::DB_DSN_PREFIX . ':Server=' . self::DB_HOST . ';Database=' . self::DB_NAME;
        } else {
            $dsn = self::DB_DSN_PREFIX . ':host=' . self::DB_HOST . ';dbname=' . self::DB_NAME;
        }
        $this->db = new CDbConnection($dsn, self::DB_USER, self::DB_PASS);
        if (self::DB_DSN_PREFIX == 'sqlsrv') {
            $this->db->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
        }
        try {
            $this->db->active = true;
        } catch (Exception $e) {
            $schemaFile = realpath(dirname(__FILE__) . '/../data/mssql.sql');
            $this->markTestSkipped("Please read {$schemaFile} for details on setting up the test environment for MSSQL test case.");
        }
        $tables = array('comments', 'post_category', 'posts', 'categories', 'profiles', 'users', 'items', 'orders', 'types');
        foreach ($tables as $table) {
            $sql = <<<EOD
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[{$table}]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[{$table}]
EOD;
            $this->db->createCommand($sql)->execute();
        }
        $rawSqls = file_get_contents(dirname(__FILE__) . '/../data/mssql.sql');
        // remove comments from SQL
        $sqls = '';
        foreach (array_filter(explode("\n", $rawSqls)) as $line) {
            if (substr($line, 0, 2) == '--') {
                continue;
            }
            $sqls .= $line . "\n";
        }
        // run SQL
        foreach (explode('GO', $sqls) as $sql) {
            if (trim($sql) !== '') {
                $this->db->createCommand($sql)->execute();
            }
        }
        CActiveRecord::$db = $this->db;
    }
开发者ID:salem-dev-acc,项目名称:yiiapp,代码行数:49,代码来源:CMssqlTest.php

示例4: connectDb

 /**
  * 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;
 }
开发者ID:cebe,项目名称:chive,代码行数:30,代码来源:Controller.php


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