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


PHP Connection::connect方法代码示例

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


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

示例1: getConnection

 /**
  * @return Connection
  */
 public function getConnection()
 {
     if (false === $this->connection->ping()) {
         $this->connection->close();
         $this->connection->connect();
     }
     return $this->connection;
 }
开发者ID:krowinski,项目名称:php-mysql-replication,代码行数:11,代码来源:MySQLRepository.php

示例2: pingIt

 protected function pingIt(Connection $con)
 {
     if ($con->ping() === false) {
         $con->close();
         $con->connect();
     }
     return $con;
 }
开发者ID:arnulfojr,项目名称:qcharts,代码行数:8,代码来源:DynamicEntityManager.php

示例3: isConnected

 /**
  * Test if is connected
  *
  * @param bool $forceConnection
  * @return bool
  */
 public function isConnected($forceConnection = false)
 {
     if ($forceConnection) {
         $this->connection->connect();
     }
     return $this->connection->isConnected();
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:13,代码来源:AdoDbAdapter.php

示例4: connect

 /**
  * Connects to the database.
  *
  * @return boolean
  */
 public function connect()
 {
     if ($connected = $this->connection->connect()) {
         $this->events->dispatch(Events::postConnect, new Event\ConnectionEvent($this));
     }
     return $connected;
 }
开发者ID:jacobjjc,项目名称:PageKit-framework,代码行数:12,代码来源:Connection.php

示例5: setupConfigurationDbal

 /**
  * setup configuration for Doctrine Dbal.
  * 
  * @param array $db_config array config for override the default configuration.
  */
 public function setupConfigurationDbal(array $db_config = [])
 {
     $dbal_config = new Configuration();
     if (empty($db_config)) {
         //setup connection configuration.
         $config = new SystemConfig();
         $config->load('db');
         $db_params = $config->get('ALL', 'db');
         unset($config, $db_params['table_prefix']);
     } else {
         $db_params = $db_config;
         unset($db_params['table_prefix']);
     }
     $dbal_config->setSQLLogger(new \System\Libraries\Db\Logger());
     try {
         $this->Conn = DriverManager::getConnection($db_params, $dbal_config);
         $this->Conn->connect();
     } catch (\Doctrine\DBAL\DBALException $e) {
         http_response_code(500);
         echo $e->getMessage();
         exit;
     }
     $this->Conn->setFetchMode(\PDO::FETCH_OBJ);
     unset($dbal_config, $db_params);
 }
开发者ID:AgniCMS,项目名称:agni-framework,代码行数:30,代码来源:Bootstrap.php

示例6: connectDatabase

 private function connectDatabase(OutputInterface $output)
 {
     $param = array();
     $param['host'] = $this->dialog->ask($output, '<question>Where is your database server? [localhost]</question> ', 'localhost');
     $param['user'] = $this->dialog->ask($output, '<question>What is your database username? [root]</question> ', 'root');
     $param['password'] = $this->dialog->ask($output, '<question>What is your database password?</question> ', '');
     $param['driver'] = 'pdo_mysql';
     // Save dbName for later use to create database
     $this->dbName = $this->dialog->ask($output, '<question>What is your database name? [BungaWire]</question> ', 'BungaWire');
     $output->writeln('');
     // Write empty line for easy read
     $config = new Configuration();
     $this->dbConnection = DriverManager::getConnection($param, $config);
     $this->dbConnection->connect();
     if ($this->dbConnection->isConnected() === false) {
         $output->writeln('Database connection failed, please check your setting');
         $output->writeln('You connection configuration is:');
         $output->writeln('host: ' . $param['host']);
         $output->writeln('user: ' . $param['user']);
         $output->writeln('password: ' . $param['password']);
         $output->writeln('Database Name: ' . $param['dbname']);
         $output->writeln('Driver: ' . $param['driver']);
         $output->writeln($this->dbConnection->errorInfo());
         $output->writeln('Please try again!');
         $this->connectDatabase($output);
     } else {
         $output->writeln('Database connected!');
     }
 }
开发者ID:gusdecool,项目名称:bunga-wire,代码行数:29,代码来源:InstallRun.php

示例7: setUp

 protected function setUp()
 {
     try {
         $this->con = DriverManager::getConnection(array('driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'dbname' => 'testdb'));
         $this->con->connect();
     } catch (\Exception $e) {
         $this->markTestSkipped('Unable to connect to the database: ' . $e->getMessage());
     }
 }
开发者ID:JoseGMaestre,项目名称:Cupon_check,代码行数:9,代码来源:AclProviderBenchmarkTest.php

示例8: getAll

 /**
  * @return Job[]
  */
 public function getAll()
 {
     $this->conn->connect();
     $stmt = $this->conn->query("select * from {$this->table_name}");
     $stmt->setFetchMode(\PDO::FETCH_CLASS, '\\ebussola\\job\\job\\Job');
     $stmt->execute();
     $jobs = $stmt->fetchAll();
     $this->conn->close();
     return $jobs;
 }
开发者ID:ebussola,项目名称:job-schedule-se,代码行数:13,代码来源:Doctrine.php

示例9: check

 /**
  * Check Doctrine connection
  *
  * @return Result
  */
 public function check()
 {
     $result = new Result($this->label);
     try {
         $this->db->connect();
     } catch (\Exception $e) {
         $result->setSuccess(false);
         $result->setError($e->getMessage());
     }
     return $result;
 }
开发者ID:bretrzaun,项目名称:statuspage,代码行数:16,代码来源:DoctrineConnectionCheck.php

示例10: connect

 /**
  * Connect to the store.
  *
  * @throws StoreConnectionFailedException When could not connect to the store.
  */
 protected function connect()
 {
     if ($this->connected) {
         return;
     }
     try {
         $this->connection->connect();
     } catch (\Exception $e) {
         throw new StoreConnectionFailedException('DoctrineDBAL: ' . $e->getMessage(), $e->getCode(), $e);
     }
     $this->connected = true;
 }
开发者ID:michaldudek,项目名称:knit,代码行数:17,代码来源:Store.php

示例11: isTableExist

 /**
  * Check if the given table exists in a database
  *
  * @param string $tableName
  * @return bool TRUE if a table exists; otherwise, FALSE
  */
 public function isTableExist($tableName)
 {
     if (!empty($tableName)) {
         try {
             $this->connection->connect();
             return $this->connection->getSchemaManager()->tablesExist($tableName);
         } catch (\PDOException $e) {
         } catch (DBALException $e) {
         }
     }
     return false;
 }
开发者ID:ramunasd,项目名称:MigrationBundle,代码行数:18,代码来源:MigrationEvent.php

示例12: setUp

 protected function setUp()
 {
     if (!class_exists('Doctrine\\DBAL\\DriverManager')) {
         $this->markTestSkipped('The "Doctrine DBAL" library is not available');
     }
     try {
         $this->con = DriverManager::getConnection(array('driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'dbname' => 'testdb'));
         $this->con->connect();
     } catch (\Exception $e) {
         $this->markTestSkipped('Unable to connect to the database: ' . $e->getMessage());
     }
 }
开发者ID:rouffj,项目名称:symfony,代码行数:12,代码来源:AclProviderBenchmarkTest.php

示例13: connect

 /**
  * Outputs the caller method name so that accidental queries can be noticed
  *
  * Using echo() is safe, since fixtures should be enabled on the command line while running PHPUnit only!
  *
  * @return bool
  */
 public function connect()
 {
     if ($this->usesFixtures() && $this->showFixtureWarnings) {
         echo ' [SQL CONNECT BY "' . $this->getFixtureCaller() . '"] ';
     }
     return parent::connect();
 }
开发者ID:lastzero,项目名称:test-tools,代码行数:14,代码来源:Connection.php

示例14: connect

 /**
  * Explicitely opens the database connection. This is done to play nice
  * with DBAL's MasterSlaveConnection. Which, in some cases, connects to a
  * follower when fetching the executed migrations. If a follower is lagging
  * significantly behind that means the migrations system may see unexecuted
  * migrations that were actually executed earlier.
  *
  * @return bool The same value returned from the `connect` method
  */
 protected function connect()
 {
     if ($this->connection instanceof MasterSlaveConnection) {
         return $this->connection->connect('master');
     }
     return $this->connection->connect();
 }
开发者ID:doctrine,项目名称:migrations,代码行数:16,代码来源:Configuration.php

示例15: connect

 public function connect()
 {
     $ret = parent::connect();
     if ($ret) {
         $params = $this->getParams();
         if (isset($params['portability'])) {
             if ($this->_platform->getName() === "oracle") {
                 $params['portability'] = $params['portability'] & self::PORTABILITY_ORACLE;
             } else {
                 if ($this->_platform->getName() === "postgresql") {
                     $params['portability'] = $params['portability'] & self::PORTABILITY_POSTGRESQL;
                 } else {
                     if ($this->_platform->getName() === "sqlite") {
                         $params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE;
                     } else {
                         $params['portability'] = $params['portability'] & self::PORTABILITY_OTHERVENDORS;
                     }
                 }
             }
             $this->portability = $params['portability'];
         }
         if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) {
             if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {
                 // make use of c-level support for case handling
                 $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']);
             } else {
                 $this->case = $params['fetch_case'] == \PDO::CASE_LOWER ? CASE_LOWER : CASE_UPPER;
             }
         }
     }
     return $ret;
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:32,代码来源:Connection.php


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