本文整理汇总了PHP中Doctrine\DBAL\Connection::getUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::getUsername方法的具体用法?PHP Connection::getUsername怎么用?PHP Connection::getUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::getUsername方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDsn
public function getDsn()
{
$driver = $this->connection->getDriver()->getName();
$user = $this->connection->getUsername();
$pass = $this->connection->getPassword();
$host = $this->connection->getHost();
$db = $this->connection->getDatabase();
return "{$driver}://{$user}:{$pass}@{$host}/{$db}";
}
示例2: getSystemInfo
/**
* Returns the system information:
* - cpu information
* - memory size
* - php version
* - php accelerator info
* - database related info.
*
* @return array
*/
public function getSystemInfo()
{
$info = ezcSystemInfo::getInstance();
$accelerator = false;
if ($info->phpAccelerator) {
$accelerator = ['name' => $info->phpAccelerator->name, 'url' => $info->phpAccelerator->url, 'enabled' => $info->phpAccelerator->isEnabled, 'versionString' => $info->phpAccelerator->versionString];
}
return ['cpuType' => $info->cpuType, 'cpuSpeed' => $info->cpuSpeed, 'cpuCount' => $info->cpuCount, 'memorySize' => $info->memorySize, 'phpVersion' => phpversion(), 'phpAccelerator' => $accelerator, 'database' => ['type' => $this->connection->getDatabasePlatform()->getName(), 'name' => $this->connection->getDatabase(), 'host' => $this->connection->getHost(), 'username' => $this->connection->getUsername()]];
}
示例3: createConfigFile
private function createConfigFile(OutputInterface $output)
{
$template = file_get_contents(__DIR__ . '/config.php.bak');
$result = str_replace(array('{{host}}', '{{database}}', '{{user}}', '{{password}}'), array($this->dbConnection->getHost(), $this->dbName, $this->dbConnection->getUsername(), $this->dbConnection->getPassword()), $template);
$filename = __DIR__ . '/../../../../site/config.php';
file_put_contents($filename, $result);
chmod($filename, 0644);
$output->writeln('Create config file success with chmod 644');
}
示例4: getAllMigrations
private function getAllMigrations($path)
{
$files = glob($path . '/*.sql');
$migrations = array();
foreach ($files as $file) {
$basefile = basename($file);
$sql = file_get_contents($file);
$revision = $this->getRevision($basefile);
if (isset($migrations[$revision])) {
throw new \RuntimeException(sprintf("Duplicate revision number '%d' is not allowed.", $revision));
}
if (strpos($sql, '--//@UNDO') !== false) {
throw new \RuntimeException('No support for DBDeploy "--//@UNDO" feature.');
}
$migrations[$revision] = array('change_number' => $revision, 'sql' => $sql, 'file' => $file, 'description' => $basefile, 'applied_by' => $this->connection->getUsername());
}
ksort($migrations, SORT_NATURAL);
return $migrations;
}
示例5: testGetUsername
public function testGetUsername()
{
$this->assertEquals('root', $this->_conn->getUsername());
}
示例6: create
public static function create(Application $app, Connection $connection, \SplFileInfo $data_template)
{
if (!file_exists($data_template->getRealPath())) {
throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist");
}
$sql = 'SELECT sbas_id
FROM sbas
WHERE host = :host AND port = :port AND dbname = :dbname
AND user = :user AND pwd = :password';
$host = $connection->getHost();
$port = $connection->getPort();
$dbname = $connection->getDatabase();
$user = $connection->getUsername();
$password = $connection->getPassword();
$params = [':host' => $host, ':port' => $port, ':dbname' => $dbname, ':user' => $user, ':password' => $password];
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
return $app['phraseanet.appbox']->get_databox((int) $row['sbas_id']);
}
try {
$sql = 'CREATE DATABASE `' . $dbname . '`
CHARACTER SET utf8 COLLATE utf8_unicode_ci';
$stmt = $connection->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
} catch (\Exception $e) {
}
$sql = 'USE `' . $dbname . '`';
$stmt = $connection->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'SELECT MAX(ord) as ord FROM sbas';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
$ord = $row['ord'] + 1;
}
$sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd)
VALUES (null, :ord, :host, :port, :dbname, "MYSQL", :user, :password)';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute([':ord' => $ord, ':host' => $host, ':port' => $port, ':dbname' => $dbname, ':user' => $user, ':password' => $password]);
$stmt->closeCursor();
$sbas_id = (int) $app['phraseanet.appbox']->get_connection()->lastInsertId();
$app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$databox->insert_datas();
$databox->setNewStructure($data_template, $app['conf']->get(['main', 'storage', 'subdefs', 'default-dir']));
return $databox;
}
示例7: formatDSN
/**
* @todo make the mysql bit dynamic
* @param Connection $connection
*/
private function formatDSN(Connection $connection)
{
$driver_name = $this->getPropelDriverName($connection->getDriver());
if ($connection->getDriver()->getName() == 'pdo_sqlite') {
return sprintf('%s://hack.nl/%s', $driver_name, $connection->getDatabase());
}
$params = $connection->getParams();
return sprintf('%s://%s:%s@%s%s/%s?encoding=%s', $driver_name, $connection->getUsername(), $connection->getPassword(), $connection->getHost(), $connection->getPort() ? ':' . $connection->getPort() : '', $connection->getDatabase(), isset($params['charset']) ? $params['charset'] : 'utf8');
}
示例8: getUsername
/**
* {@inheritdoc}
*/
public function getUsername()
{
$params = $this->getParams();
return isset($params['user']) ? $params['user'] : parent::getUsername();
}
示例9: collect
/**
* Collects information about the database eZ Platform is using.
* - type
* - name
* - host
* - username
*
* @return Value\DatabaseSystemInfo
*/
public function collect()
{
return new Value\DatabaseSystemInfo(['type' => $this->connection->getDatabasePlatform()->getName(), 'name' => $this->connection->getDatabase(), 'host' => $this->connection->getHost(), 'username' => $this->connection->getUsername()]);
}
示例10: loadGeoData
/**
* Fill datatabase with geodata
*
* @param Connection $connection
*
* @return boolean
*/
public function loadGeoData($connection)
{
$which_output = '';
$which_ret = '';
@exec('which mysql', $which_output, $which_ret);
if (is_array($which_output) && isset($which_output[0])) {
$mysql_client_command = $which_output[0];
if (!$this->withMysqlAllIsOk($mysql_client_command)) {
return false;
}
$last_dir = getcwd();
$work_dir = __DIR__ . '/../../../../install/Resources/sql';
chdir($work_dir);
$db_host = $connection->getHost();
$db_port = $connection->getPort();
$db_user = $connection->getUsername();
$db_pass = $connection->getPassword();
$db_name = $connection->getDatabase();
$access_params = '';
$access_params .= ' -h ' . escapeshellarg($db_host);
if (!empty($db_port)) {
$access_params .= ' -P ' . escapeshellarg('' . $db_port);
}
$access_params .= ' -u ' . escapeshellarg($db_user);
if (!empty($db_pass)) {
$access_params .= ' -p' . escapeshellarg($db_pass);
}
$access_params .= ' -D ' . escapeshellarg($db_name);
$cmd_string = escapeshellcmd($mysql_client_command) . $access_params . ' --local-infile=1 < ' . 'geonames.sql';
$cmd_output = array();
$cmd_retval = 0;
exec($cmd_string, $cmd_output, $cmd_retval);
chdir($last_dir);
if (!empty($cmd_retval)) {
return false;
}
return true;
}
}
示例11: getDBConn
private function getDBConn(InputInterface $input, OutputInterface $output, Connection $abConn, DialogHelper $dialog)
{
$dbConn = $template = null;
if (!$input->getOption('databox')) {
do {
$retry = false;
$dbName = $dialog->ask($output, 'DataBox name, will not be created if empty : ', null);
if ($dbName) {
try {
$dbConn = $this->container['dbal.provider']->get(['host' => $abConn->getHost(), 'port' => $abConn->getPort(), 'user' => $abConn->getUsername(), 'password' => $abConn->getPassword(), 'dbname' => $dbName]);
$dbConn->connect();
$output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n");
do {
$template = $dialog->ask($output, 'Choose a language template for metadata structure, available are fr (french) and en (english) (en) : ', 'en');
} while (!in_array($template, ['en', 'fr']));
$output->writeln("\n\tLanguage selected is <info>'{$template}'</info>\n");
} catch (\Exception $e) {
$retry = true;
}
} else {
$output->writeln("\n\tNo databox will be created\n");
}
} while ($retry);
} else {
$dbConn = $this->container['dbal.provider']->get(['host' => $input->getOption('db-host'), 'port' => $input->getOption('db-port'), 'user' => $input->getOption('db-user'), 'password' => $input->getOption('db-password'), 'dbname' => $input->getOption('databox')]);
$dbConn->connect();
$output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n");
$template = $input->getOption('db-template') ?: 'en';
}
return [$dbConn, $template];
}
示例12: process
//.........这里部分代码省略.........
FROM `source` t
LEFT JOIN `source` parent ON t.`parent` = parent.`id`
WHERE t.`__depth` = @depth
ORDER BY t.`sort` ASC;');
$this->db->query('UPDATE `source` t
JOIN `tmp.Fill` f USING(`id`)
SET t.`__position` = f.`__position`,
t.`__position_depth` = f.`__position_depth`
;');
}
$this->db->query('SELECT @increment := 0;');
$this->db->query('TRUNCATE `tmp.Fill`;');
// Flatten the position numbers
$this->db->query('INSERT INTO `tmp.Fill`
SELECT
t.`id`,
@increment := @increment+1 AS `__position`,
0 AS `__position_depth`
FROM `source` t
ORDER BY t.`__position` ASC;');
// And then back to source table
$this->db->executeUpdate('UPDATE `source` t
JOIN `tmp.Fill` f USING(`id`)
SET t.`__position` = f.`__position`
;');
// Relative position
$this->db->query('SELECT @increment := 0;');
$this->db->query('TRUNCATE `tmp.Fill`;');
$this->db->query('INSERT INTO `tmp.Fill`
SELECT s.`id`, CAST(s.__position - r.__position AS SIGNED) AS `__position`, 0 AS `__position_depth`
FROM `source` s
LEFT JOIN `source` r ON s.`__root` = r.`id`;');
$this->db->query('UPDATE `source` t
JOIN `tmp.Fill` f USING(`id`)
SET t.`__position_relative` = f.`__position`;');
if ($calculateDeltas) {
$this->db->query('ALTER TABLE source
ADD INDEX `root_depth` (`__root`, `__depth`),
ADD INDEX `root_relpos` (`__root`, `__position_relative`),
ADD INDEX `root_depth_pos` (`__root`, `__depth`, `__position_depth`)
;');
$this->db->query('CREATE VIEW `out.source` AS
SELECT
source.`id` AS `' . $idColumn . '`,
source.`__root` AS `root`,
source.`__position` AS `position`,
source.`__position_relative` AS `position_relative`,
source.`__depth` AS `depth`,
IF(source.`__timestamp` - root.`__timestamp` < 0, 0, source.`__timestamp` - root.`__timestamp`)
AS `time_delta_runsum`,
COALESCE(
(source.`__timestamp` - previous.`__timestamp`),
(source.`__timestamp` - previous_2.`__timestamp`),
(source.`__timestamp` - previous_3.`__timestamp`),
0
) AS `time_delta`
FROM
`source` source
LEFT JOIN `source` root USE INDEX(`root_depth`)
ON source.`__root` = root.`__root` AND root.`__depth` = 0
# Same level, direct previous
LEFT JOIN `source` previous USE INDEX(`root_relpos`)
ON source.`__root`= previous.`__root` AND
previous.`__depth` = source.`__depth` AND
previous.`__position_relative` = source.`__position_relative` - 1
# One level up, direct previous
LEFT JOIN `source` previous_2 USE INDEX(`root_relpos`)
ON source.`__root`= previous_2.`__root` AND
previous_2.`__depth` = source.`__depth` - 1 AND
previous_2.`__position_relative` = source.`__position_relative` - 1
# No direct previous, finding closest previous on the same level
LEFT JOIN `source` previous_3 USE INDEX(`root_depth_pos`)
ON source.`__root`= previous_3.`__root` AND
previous_3.`__depth` = source.`__depth` AND
previous_3.`__position_depth` = source.`__position_depth` - 1
;');
} else {
$this->db->query('CREATE VIEW `out.source` AS
SELECT
`id` AS `' . $idColumn . '`,
`__root` AS `root`,
`__position` AS `position`,
`__position_relative` AS `position_relative`,
`__depth` AS `depth`
FROM
`source`;');
}
// Export Data
$outFile = $outDirectory . DIRECTORY_SEPARATOR . 'destination.csv';
$command = 'mysql -u ' . $this->db->getUsername() . ' -p' . $this->db->getPassword() . ' -h ' . $this->db->getHost() . ' ' . $this->db->getDatabase() . ' --default-character-set=UTF8 --batch --execute ' . escapeshellarg('SELECT * FROM `out.source`;') . ' --quick | sed \'s/\\t/,/g\' > ' . $outFile;
$process = new Process($command);
$process->run();
if ($process->getExitCode() != 0) {
$error = $process->getErrorOutput();
if (!$error) {
$error = $process->getOutput();
}
throw new DBALException('MySQL export error: ' . $error);
}
}
示例13: createConfigFile
private function createConfigFile(Connection $abConn, $serverName, $binaryData)
{
$config = $this->app['configuration.store']->initialize()->getConfig();
$config['main']['database']['host'] = $abConn->getHost();
$config['main']['database']['port'] = $abConn->getPort();
$config['main']['database']['user'] = $abConn->getUsername();
$config['main']['database']['password'] = $abConn->getPassword();
$config['main']['database']['dbname'] = $abConn->getDatabase();
$config['main']['database']['driver'] = 'pdo_mysql';
$config['main']['database']['charset'] = 'UTF8';
$config['main']['binaries'] = $binaryData;
$config['servername'] = $serverName;
$config['main']['key'] = md5(mt_rand(100000000, 999999999));
$this->app['configuration.store']->setConfig($config);
}