本文整理汇总了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;
}
示例2: pingIt
protected function pingIt(Connection $con)
{
if ($con->ping() === false) {
$con->close();
$con->connect();
}
return $con;
}
示例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();
}
示例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;
}
示例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);
}
示例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!');
}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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();
}
示例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();
}
示例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;
}