本文整理汇总了PHP中Propel\Runtime\Propel::getAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::getAdapter方法的具体用法?PHP Propel::getAdapter怎么用?PHP Propel::getAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\Propel
的用法示例。
在下文中一共展示了Propel::getAdapter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$connection = Propel::getConnection($input->getOption('connection'));
$adapter = Propel::getAdapter($connection->getName());
if (!$adapter instanceof MysqlAdapter) {
return $output->writeln('<error>This command is MySQL only.</error>');
}
if (!$input->getOption('force')) {
return $output->writeln('<error>You have to use the "--force" option to drop some tables.</error>');
}
$tablesToDelete = $input->getArgument('table');
$nbTable = count($tablesToDelete);
$tablePlural = $nbTable > 1 || $nbTable == 0 ? 's' : '';
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
$count = $nbTable ?: 'all';
$this->writeSection($output, 'WARNING: you are about to drop ' . $count . ' table' . $tablePlural . ' in production !', 'bg=red;fg=white');
if (false === $this->askConfirmation($input, $output, 'Are you sure ? (y/n) ', false)) {
$output->writeln('<info>Aborted, nice decision !</info>');
return -2;
}
}
$showStatement = $connection->prepare('SHOW TABLES;');
$showStatement->execute();
$allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN);
if ($nbTable) {
foreach ($tablesToDelete as $tableToDelete) {
if (!array_search($tableToDelete, $allTables)) {
throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete));
}
}
} else {
$tablesToDelete = $allTables;
}
$connection->exec('SET FOREIGN_KEY_CHECKS = 0;');
array_walk($tablesToDelete, function (&$table, $key, $dbAdapter) {
$table = $dbAdapter->quoteIdentifierTable($table);
}, $adapter);
$tablesToDelete = join(', ', $tablesToDelete);
if ('' !== $tablesToDelete) {
$connection->exec('DROP TABLE ' . $tablesToDelete . ' ;');
$output->writeln(sprintf('Table' . $tablePlural . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
} else {
$output->writeln('<info>No tables have been dropped</info>');
}
$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
}
示例2: testNumberOfQueriesForMakeUniqSlug
public function testNumberOfQueriesForMakeUniqSlug()
{
Table13Query::create()->deleteAll();
$con = Propel::getServiceContainer()->getConnection(Table13TableMap::DATABASE_NAME);
$adapter = Propel::getAdapter(Table13TableMap::DATABASE_NAME);
$expectedCount = 4;
if ($adapter instanceof PgsqlAdapter) {
$expectedCount++;
//because of the SELECT nextval(...) query
}
for ($i = 0; $i < 5; $i++) {
$nbQuery = $con->getQueryCount();
$t = new Table13();
$t->setTitle('Hello, World');
$t->save($con);
$this->assertLessThanOrEqual($expectedCount, $con->getQueryCount() - $nbQuery, "no more than {$expectedCount} query to get a slug when it already exist");
}
}