本文整理汇总了PHP中db_drop_table函数的典型用法代码示例。如果您正苦于以下问题:PHP db_drop_table函数的具体用法?PHP db_drop_table怎么用?PHP db_drop_table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_drop_table函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
protected function tearDown()
{
// The DatabaseExpirableStorage class has a destructor which deletes rows
// from the key_value_expire table. We need to make sure the destructor
// runs before the table is deleted.
$this->container->set('keyvalue.expirable', NULL);
db_drop_table('key_value_expire');
parent::tearDown();
}
示例2: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $user, $language;
// In case a fatal error occurred that was not in the test process read the
// log to pick up any fatal errors.
simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
$emailCount = count(variable_get('drupal_test_email_collector', array()));
if ($emailCount) {
$message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.');
$this->pass($message, t('E-mail'));
}
// Delete temporary files directory.
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10));
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
foreach ($schema as $name => $table) {
db_drop_table($name);
}
// Get back to the original connection.
Database::removeConnection('default');
Database::renameConnection('simpletest_original_default', 'default');
// Restore original shutdown callbacks array to prevent original
// environment of calling handlers from test run.
$callbacks =& drupal_register_shutdown_function();
$callbacks = $this->originalShutdownCallbacks;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements('', FALSE, TRUE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
示例3: assertFieldChange
/**
* Asserts that a field can be changed from one spec to another.
*
* @param $old_spec
* The beginning field specification.
* @param $new_spec
* The ending field specification.
*/
protected function assertFieldChange($old_spec, $new_spec)
{
$table_name = 'test_table_' . $this->counter++;
$table_spec = array('fields' => array('serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'test_field' => $old_spec), 'primary key' => array('serial_column'));
db_create_table($table_name, $table_spec);
$this->pass(format_string('Table %table created.', array('%table' => $table_name)));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $old_spec);
// Remove inserted rows.
db_truncate($table_name)->execute();
// Change the field.
db_change_field($table_name, 'test_field', 'test_field', $new_spec);
// Check the field was changed.
$this->assertFieldCharacteristics($table_name, 'test_field', $new_spec);
// Clean-up.
db_drop_table($table_name);
}
示例4: hook_field_storage_purge_field
/**
* Remove field storage information when a field record is purged.
*
* Called from field_purge_field() to allow the field storage module
* to remove field information when a field is being purged.
*
* @param $field
* The field being purged.
*/
function hook_field_storage_purge_field($field)
{
$table_name = _field_sql_storage_tablename($field);
$revision_name = _field_sql_storage_revision_tablename($field);
db_drop_table($table_name);
db_drop_table($revision_name);
}
示例5: tearDown
protected function tearDown()
{
db_drop_table('key_value_expire');
db_drop_table('semaphore');
parent::tearDown();
}
示例6: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix, $user, $language;
// In case a fatal error occured that was not in the test process read the
// log to pick up any fatal errors.
$db_prefix_temp = $db_prefix;
$db_prefix = $this->originalPrefix;
simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE);
$db_prefix = $db_prefix_temp;
$emailCount = count(variable_get('drupal_test_email_collector', array()));
if ($emailCount) {
$message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount));
$this->pass($message, t('E-mail'));
}
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory.
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10));
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements('', FALSE, TRUE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
}
示例7: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
function tearDown()
{
global $db_prefix;
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
simpletest_clean_temporary_directory(file_directory_path());
variable_set('file_directory_path', $this->original_file_directory);
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
$db_prefix = $this->db_prefix_original;
$this->_logged_in = FALSE;
$this->curlClose();
}
parent::tearDown();
}
示例8: synchronize
public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false)
{
/* @var $node FieldNode */
$object = $node->getValue();
if (!is_array($object)) {
$object = array();
}
if (!isset($object['type'])) {
$context->logCritical(sprintf("%s: has no type", $node->getPath()));
}
$name = $node->getName();
$type = $object['type'];
$typeInfo = field_info_field_types($type);
if (empty($typeInfo)) {
$context->logCritical(sprintf("%s: type %s does not exist", $node->getPath(), $type));
}
if ($this->exists($node, $context)) {
$existing = $this->getExistingObject($node, $context);
} else {
$existing = null;
}
if (array_key_exists('settings', $object) && !is_array($object['settings'])) {
$context->log(sprintf("%s: no settings provided, defaulting with empty array", $node->getPath()));
$object['settings'] = array();
}
$object['field_name'] = $name;
if (empty($object['cardinality'])) {
$object['cardinality'] = 1;
}
// Consistency check, prior to do anything, ensure the database tables
// are not already there, this happens, sometimes
if (!$existing) {
if (empty($object['storage']) || 'field_sql_storage' === $object['storage']['type']) {
// Prevents warning on unspecified key
if (!isset($object['deleted'])) {
$object['deleted'] = false;
}
$tables = [_field_sql_storage_tablename($object), _field_sql_storage_revision_tablename($object)];
foreach ($tables as $table) {
if (db_table_exists($table)) {
$context->logDataloss(sprintf("%s: %s: table already exists prior to creating field", $node->getPath(), $table));
// If code has not broken here, then go for deletion
db_drop_table($table);
}
}
}
}
if ($existing) {
$doDelete = false;
$eType = $existing['type'];
// Ensure the cardinality change if any is safe to proceed with
$cardinality = $object['cardinality'] - $existing['cardinality'];
if (0 !== $cardinality) {
if (0 < $cardinality || -1 == $object['cardinality']) {
$context->log(sprintf("%s: safe cardinality change", $node->getPath()));
} else {
// @todo Ensure there is data we can save in field
if (false) {
$context->log(sprintf("%s: safe cardinality change due to data shape", $node->getPath()));
} else {
$context->logDataloss(sprintf("%s: unsafe cardinality change", $node->getPath()));
}
}
}
if ($type !== $eType) {
$doDelete = true;
$instances = $this->getInstances($name);
if (empty($instances)) {
$context->logWarning(sprintf("%s: type change (%s -> %s): no instances", $node->getPath(), $type, $eType));
} else {
// @todo Ensure there is data if there is instances
if (false) {
$context->logWarning(sprintf("%s: type change (%s -> %s): existing instances are empty", $node->getPath(), $type, $eType));
} else {
// @todo Safe should ensure schema is the same
if (false) {
$context->logWarning(sprintf("%s: type change (%s -> %s): field schema is the same", $node->getPath(), $type, $eType));
} else {
$context->logDataloss(sprintf("%s: type change (%s -> %s): data loss detected", $node->getPath(), $type, $eType));
}
}
}
}
if ($doDelete) {
$this->deleteExistingObject($node, $context);
field_create_field($object);
// @todo Recreate instances
} else {
field_update_field($object);
}
} else {
field_create_field($object);
}
}
示例9: tearDown
protected function tearDown()
{
db_drop_table('key_value');
parent::tearDown();
}
示例10: dropTable
/**
* Drop a datastore table
*/
private function dropTable($table_name)
{
$table = data_get_table($table_name);
if ($table) {
$table->drop();
} elseif (db_table_exists($table_name)) {
db_drop_table($table_name);
}
}
示例11: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix, $user;
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
file_unmanaged_delete_recursive(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Close the CURL handler.
$this->curlClose();
}
}
示例12: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix, $user, $language;
$emailCount = count(variable_get('simpletest_emails', array()));
if ($emailCount) {
$message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount));
$this->pass($message, t('E-mail'));
}
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
file_unmanaged_delete_recursive(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
}
示例13: dida_setup_data_test
function dida_setup_data_test()
{
global $error, $database;
if (db_connect('default')) {
$table = array('description' => '测试', 'fields' => array('id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => false, 'default' => 0, 'description' => '测试'), 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => '测试')), 'indexes' => array('tid' => array('tid')), 'primary key' => array('id'));
if (db_is_table('dida_test')) {
if (!db_drop_table('dida_test')) {
$error[] = '没有数据库表删除权限';
}
}
// 测试表
if (db_create_table('dida_test', $table)) {
if (db_exec('INSERT INTO {dida_test} (tid, name) VALUES (:tid, :name)', array(':tid' => 10, ':name' => 'test'))) {
if (db_query('SELECT * FROM {dida_test}')) {
if (db_exec('UPDATE {dida_test} SET name = :name WHERE tid = :tid', array(':tid' => 10, ':name' => 'newtest'))) {
if (db_exec('DELETE FROM {dida_test} WHERE tid = 10')) {
if (!db_drop_table('dida_test')) {
$error[] = '没有数据库表删除权限';
} else {
if (db_is_table('system')) {
$error[] = '系统配置表已经存在,该数据库中是否已经存在一个程序,建议使用全新数据库,或设置表前缀';
}
}
} else {
$error[] = '没有数据删除权限';
}
} else {
$error[] = '没有数据更新权限';
}
} else {
$error[] = '没有数据查询权限';
}
} else {
$error[] = '没有表写入权限';
}
} else {
$error[] = '没有表创建权限';
}
} else {
$error[] = '连接数据库失败,请检查配置,或<a href="install.php?setup=1&clear=1">重新开始安装</a>';
}
if (empty($error)) {
dd_goto(f('install.php?setup=4'));
}
}
示例14: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $user, $language, $settings, $config_directories;
// In case a fatal error occurred that was not in the test process read the
// log to pick up any fatal errors.
simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
$emailCount = count(state_get('test_email_collector', array()));
if ($emailCount) {
$message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.');
$this->pass($message, t('E-mail'));
}
// Delete temporary files directory.
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10));
// Remove all prefixed tables.
$connection_info = Database::getConnectionInfo('default');
$tables = db_find_tables($connection_info['default']['prefix']['default'] . '%');
if (empty($tables)) {
$this->fail('Failed to find test tables to drop.');
}
$prefix_length = strlen($connection_info['default']['prefix']['default']);
foreach ($tables as $table) {
if (db_drop_table(substr($table, $prefix_length))) {
unset($tables[$table]);
}
}
if (!empty($tables)) {
$this->fail('Failed to drop all prefixed tables.');
}
// Get back to the original connection.
Database::removeConnection('default');
Database::renameConnection('simpletest_original_default', 'default');
// Delete the database table prefix record.
db_delete('simpletest_prefix')->condition('test_id', $this->testId)->condition('prefix', $this->databasePrefix)->execute();
// Set the configuration direcotires back to the originals.
$config_directories = $this->originalConfigDirectories;
// Restore the original settings.
$settings = $this->originalSettings;
// Restore original shutdown callbacks array to prevent original
// environment of calling handlers from test run.
$callbacks =& backdrop_register_shutdown_function();
$callbacks = $this->originalShutdownCallbacks;
// Return the user to the original one.
$user = $this->originalUser;
backdrop_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements_reset();
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset public files directory.
$GLOBALS['conf']['file_public_path'] = $this->originalFileDirectory;
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
示例15: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix;
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
simpletest_clean_temporary_directory(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($ret, $name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Ensure that the internal logged in variable is reset.
$this->isLoggedIn = FALSE;
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
// Rebuild caches.
$this->refreshVariables();
// Close the CURL handler.
$this->curlClose();
}
}