本文整理汇总了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);
}
示例2: __construct
public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
$this->defaultSchema = $adapter->getCurrentSchema() ?: self::DEFAULT_SCHEMA;
}