本文整理匯總了PHP中Doctrine\DBAL\Connection::getParams方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::getParams方法的具體用法?PHP Connection::getParams怎麽用?PHP Connection::getParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::getParams方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getQuery
/**
* @throws \RuntimeException
* @return string
*/
public function getQuery()
{
$config = $this->connection->getParams();
$driver = $config['driver'];
if (!isset($this->configClasses[$driver])) {
throw new \RuntimeException('Driver "%s" not found');
}
/** @var PdoMysql $className */
$className = $this->configClasses[$driver];
return $className::getPlainSql();
}
示例2: getDatabase
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return null;
}
示例3: add
/**
* Add a connection to the pool
*
* @param Connection $connection
*/
public function add(Connection $connection)
{
$key = md5(serialize($connection->getParams()));
if (isset($this->connections[$key]) && $connection !== $this->connections[$key]) {
throw new \InvalidArgumentException('Expects a non registered connection.');
}
$this->connections[$key] = $connection;
}
示例4: getDatabase
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DATABASE()')->fetchColumn();
}
示例5: __construct
/**
* @param Connection $conn
* @param string $generatorTableName
*/
public function __construct(Connection $conn, $generatorTableName = 'sequences')
{
$params = $conn->getParams();
if ($params['driver'] == 'pdo_sqlite') {
throw new \Doctrine\DBAL\DBALException("Cannot use TableGenerator with SQLite.");
}
$this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager());
$this->generatorTableName = $generatorTableName;
}
示例6: dropDatabaseForConnection
protected function dropDatabaseForConnection(Connection $connection, OutputInterface $output)
{
$params = $connection->getParams();
$name = isset($params['path']) ? $params['path'] : $params['dbname'];
try {
$connection->getSchemaManager()->dropDatabase($name);
$output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name));
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}
示例7: createNewscoopDatabase
/**
* Create Newscoop Database
*
* @param Connection $connection
*/
public function createNewscoopDatabase($connection)
{
$params = $connection->getParams();
if (isset($params['master'])) {
$params = $params['master'];
}
unset($params['dbname']);
$tmpConnection = DriverManager::getConnection($params);
$name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($connection->getDatabase());
$tmpConnection->getSchemaManager()->createDatabase($name);
unset($tmpConnection);
$this->logger->addInfo('Database ' . $name . ' created');
}
示例8: getPanel
/**
* @return string
*/
public function getPanel()
{
if (empty($this->queries)) {
return '';
}
$connParams = $this->connection->getParams();
if ($connParams['driver'] === 'pdo_sqlite' && isset($connParams['path'])) {
$host = 'path: ' . basename($connParams['path']);
} else {
$host = sprintf('host: %s%s/%s', $this->connection->getHost(), ($p = $this->connection->getPort()) ? ':' . $p : '', $this->connection->getDatabase());
}
return $this->renderStyles() . sprintf('<h1>Queries: %s %s, %s</h1>', count($this->queries), $this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '', $host) . '<div class="nette-inner tracy-inner nette-Doctrine2Panel">' . implode('<br>', array_filter([$this->renderPanelCacheStatistics(), $this->renderPanelQueries()])) . '</div>';
}
示例9: __construct
public function __construct(Connection $db = null, $tableName, $tableAlias = null, $tablesAliases = null)
{
$this->db = $db;
$this->tableName = $tableName;
$this->tableAlias = $tableAlias;
$this->tablesAliases = $tablesAliases;
$this->table = $this->tableAlias !== null ? $this->tableAlias : "`{$this->tableName}`";
if ($db !== null && $db->getParams()['driver'] !== 'pdo_sqlite') {
$tableColumns = $db->executeQuery("DESCRIBE {$tableName}")->fetchAll(\PDO::FETCH_COLUMN);
$this->isTimestampable = count(array_intersect(['created_at', 'updated_at'], $tableColumns)) == 2;
$this->isSoftdeletable = in_array('deleted_at', $tableColumns);
}
}
示例10: createSchemaConfig
/**
* Creates the configuration for this schema.
*
* @return \Doctrine\DBAL\Schema\SchemaConfig
*/
public function createSchemaConfig()
{
$schemaConfig = new SchemaConfig();
$schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
$searchPaths = $this->getSchemaSearchPaths();
if (isset($searchPaths[0])) {
$schemaConfig->setName($searchPaths[0]);
}
$params = $this->_conn->getParams();
if (isset($params['defaultTableOptions'])) {
$schemaConfig->setDefaultTableOptions($params['defaultTableOptions']);
}
return $schemaConfig;
}
示例11: createDatabaseForConnection
protected function createDatabaseForConnection(Connection $connection, OutputInterface $output)
{
$params = $connection->getParams();
$name = isset($params['path']) ? $params['path'] : $params['dbname'];
unset($params['dbname']);
$tmpConnection = \Doctrine\DBAL\DriverManager::getConnection($params);
try {
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name));
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
$tmpConnection->close();
}
示例12: __construct
/**
* @param \Doctrine\DBAL\Connection $conn
*
* @throws \Doctrine\DBAL\Sharding\ShardingException
*/
public function __construct(Connection $conn)
{
$this->conn = $conn;
$params = $conn->getParams();
if (!isset($params['sharding']['federationName'])) {
throw ShardingException::missingDefaultFederationName();
}
if (!isset($params['sharding']['distributionKey'])) {
throw ShardingException::missingDefaultDistributionKey();
}
if (!isset($params['sharding']['distributionType'])) {
throw ShardingException::missingDistributionType();
}
$this->federationName = $params['sharding']['federationName'];
$this->distributionKey = $params['sharding']['distributionKey'];
$this->distributionType = $params['sharding']['distributionType'];
$this->filteringEnabled = isset($params['sharding']['filteringEnabled']) ? (bool) $params['sharding']['filteringEnabled'] : false;
}
示例13: mysql_connect
/**
* Connect using the deprecated mysql extension.
*
* This method is often required when working with some legacy admin pages.
*
* Most people won't need this, but it is here if they do.
*
* @param array $params an array of mysql connection optons that match the PDO dsn.
* If you do not specify any parameters. it will use the
* <code>apps.store.database.default</code> settings.
* @return resource an ext/mysql resource
*/
public function mysql_connect($params = null)
{
if (!extension_loaded('mysql')) {
throw new \RuntimeException('The mysql extension must be installed to use this method.');
}
$defaults = $this->conn->getParams();
$params = array_merge($defaults, (array) $params);
$link = mysql_connect($params['host'], $params['user'], $params['password'], true);
if (is_resource($link) && mysql_select_db($params['dbname'])) {
if (!isset($params['charset']) && !empty($params['charset'])) {
mysql_set_charset($params['charset']);
}
$this->link = $link;
return $this->link;
} else {
throw new RuntimeException(mysql_error(), mysql_errno());
}
}
示例14: getServerVersion
private function getServerVersion()
{
$params = $this->con->getParams();
// Explicit platform version requested (supersedes auto-detection), so we respect it.
if (isset($params['serverVersion'])) {
return $params['serverVersion'];
}
$wrappedConnection = $this->con->getWrappedConnection();
if ($wrappedConnection instanceof ServerInfoAwareConnection) {
return $wrappedConnection->getServerVersion();
}
// Support DBAL 2.4 by accessing it directly when using PDO PgSQL
if ($wrappedConnection instanceof \PDO) {
return $wrappedConnection->getAttribute(\PDO::ATTR_SERVER_VERSION);
}
// If we cannot guess the version, the empty string will mean we won't use the code for newer versions when doing version checks.
return '';
}
示例15: __construct
public function __construct(Connection $conn)
{
$this->pdo = $conn;
$params = $conn->getParams();
$driver = $params['driver'];
$commands = [];
switch ($driver) {
case 'pdo_mysql':
$commands[] = 'SET SQL_MODE=ANSI_QUOTES';
break;
case 'pdo_sqlite':
break;
case 'pdo_pgsql':
break;
case 'pdo_oci':
break;
case 'pdo_sqlsrv':
$commands[] = 'SET QUOTED_IDENTIFIER ON';
break;
}
foreach ($commands as $comm) {
$this->pdo->exec($comm);
}
}