當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。