當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Propel::getAdapter方法代碼示例

本文整理匯總了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;');
 }
開發者ID:naldz,項目名稱:cyberden,代碼行數:49,代碼來源:TableDropCommand.php

示例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");
     }
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:18,代碼來源:SluggableBehaviorTest.php


注:本文中的Propel\Runtime\Propel::getAdapter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。