当前位置: 首页>>代码示例>>PHP>>正文


PHP AdapterInterface::getCurrentSchema方法代码示例

本文整理汇总了PHP中Zend\Db\Adapter\AdapterInterface::getCurrentSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP AdapterInterface::getCurrentSchema方法的具体用法?PHP AdapterInterface::getCurrentSchema怎么用?PHP AdapterInterface::getCurrentSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Db\Adapter\AdapterInterface的用法示例。


在下文中一共展示了AdapterInterface::getCurrentSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  * Initializes database on first run then resets tables on subsequent runs.
  * 
  * @see \Spork\Test\TestCase\TestCaseService::setUp()
  * @throws \Exception on attempt to reset non temporary table
  */
 protected function setUp()
 {
     parent::setUp();
     $services = $this->getServiceLocator();
     if (null === self::$dbAdapter) {
         // initialize database connections
         if (isset($GLOBALS['DB_MAIN_SERVICE_NAME'])) {
             self::$dbAdapterName = $GLOBALS['DB_MAIN_SERVICE_NAME'];
         }
         $dbAdapterDefault = $services->get(self::$dbAdapterName);
         self::$dbSchemaDefault = $dbAdapterDefault->getCurrentSchema();
         if (isset($GLOBALS['DB_TEST_SERVICE_NAME'])) {
             self::$dbAdapter = $services->get($GLOBALS['DB_TEST_SERVICE_NAME']);
             self::$dbSchemaTest = self::$dbAdapter->getCurrentSchema();
         } else {
             self::$dbAdapter = $dbAdapterDefault;
         }
         // drop static tables
         if (null !== self::$dbSchemaTest) {
             self::$dbAdapter->query("DROP DATABASE {$this->quoteIdentifier(self::$dbSchemaTest)}", Adapter::QUERY_MODE_EXECUTE);
             self::$dbAdapter->query("CREATE DATABASE {$this->quoteIdentifier(self::$dbSchemaTest)}", Adapter::QUERY_MODE_EXECUTE);
             self::$dbAdapter->query("USE {$this->quoteIdentifier(self::$dbSchemaTest)}", Adapter::QUERY_MODE_EXECUTE);
         }
         // create test tables
         foreach ($this->getTables($dbAdapterDefault) as $table) {
             $this->createTestTable($table, $dbAdapterDefault, self::$dbAdapter);
         }
         // copy triggers
         if (null !== self::$dbSchemaTest) {
             $triggers = self::$dbAdapter->query("SHOW TRIGGERS FROM {$this->quoteIdentifier(self::$dbSchemaDefault)}", Adapter::QUERY_MODE_EXECUTE);
             foreach ($triggers as $trigger) {
                 $createTrigger = self::$dbAdapter->query("SHOW CREATE TRIGGER {$this->quoteIdentifier(self::$dbSchemaDefault)}.{$this->quoteIdentifier($trigger['Trigger'])}", Adapter::QUERY_MODE_EXECUTE);
                 self::$dbAdapter->query($createTrigger->current()['SQL Original Statement'], Adapter::QUERY_MODE_EXECUTE);
             }
         }
     } else {
         foreach ($this->getTables(self::$dbAdapter) as $table) {
             // make sure temporary tables are temporary
             if (null === self::$dbSchemaTest) {
                 $createTable = $this->getCreateTable($table, self::$dbAdapter);
                 if (strpos($createTable, 'CREATE TEMPORARY TABLE') === false) {
                     throw new \Exception("Table '{$table}' is not temporary");
                 }
             }
             // empty tables
             $result = self::$dbAdapter->query("truncate table `{$table}`", Adapter::QUERY_MODE_EXECUTE);
         }
         $allowOverride = $services->getAllowOverride();
         $services->setAllowOverride(true)->setService(self::$dbAdapterName, self::$dbAdapter)->setAllowOverride($allowOverride);
     }
     $allowOverride = $services->getAllowOverride();
     $services->setAllowOverride(true)->setService(self::$dbAdapterName, self::$dbAdapter)->setAllowOverride($allowOverride);
 }
开发者ID:sporkcode,项目名称:spork,代码行数:59,代码来源:TestCaseDb.php

示例2: __construct

 public function __construct(AdapterInterface $adapter)
 {
     $this->adapter = $adapter;
     $this->defaultSchema = $adapter->getCurrentSchema() ?: self::DEFAULT_SCHEMA;
 }
开发者ID:railsphp,项目名称:framework,代码行数:5,代码来源:CachedMetadata.php


注:本文中的Zend\Db\Adapter\AdapterInterface::getCurrentSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。