当前位置: 首页>>代码示例>>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;未经允许,请勿转载。