function demo_dump_db in Demonstration site (Sandbox / Snapshot) 6
Same name and namespace in other branches
- 8 demo.module \demo_dump_db()
- 5 database_mysql_dump.inc \demo_dump_db()
- 7 database_mysql_dump.inc \demo_dump_db()
Dump active database.
Parameters
$filename: The filename including path to write the dump to.
$options: An associative array of snapshot options, as described in demo_dump().
1 call to demo_dump_db()
- _demo_dump in ./
demo.admin.inc - Create a new snapshot.
File
- ./
database_mysql_dump.inc, line 16
Code
function demo_dump_db($filename, $options = array()) {
// Make sure we have permission to save our backup file.
$directory = dirname($filename);
if (!file_check_directory($directory, FILE_CREATE_DIRECTORY)) {
return FALSE;
}
if ($fp = fopen($filename, 'wb')) {
$header = array();
$header[] = '-- Demo module database dump';
$header[] = '-- Version ' . DEMO_DUMP_VERSION;
$header[] = '-- http://drupal.org/project/demo';
$header[] = '--';
$header[] = '-- Database: ' . _demo_get_database();
$header[] = '-- Date: ' . format_date(time(), 'small');
$header[] = '-- Server version: ' . db_version();
$header[] = '-- PHP version: ' . PHP_VERSION;
$header[] = '-- Drupal version: ' . VERSION;
// Avoid auto value for zero values (required for user id 0).
$header[] = '';
$header[] = 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";';
// Temporarily disable foreign key checks for the time of import.
$header[] = 'SET FOREIGN_KEY_CHECKS = 0;';
$header[] = '';
// Set collations for the import. PMA and mysqldump use conditional comments
// to exclude MySQL <4.1, but D6 requires >=4.1.
$header[] = 'SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;';
$header[] = 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;';
$header[] = 'SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;';
$header[] = 'SET NAMES utf8;';
$header[] = '';
fwrite($fp, implode("\n", $header));
foreach ($options['tables'] as $table => $dump_options) {
if (!_demo_table_is_view($table)) {
if ($dump_options['schema']) {
_demo_dump_table_schema($fp, $table);
}
if ($dump_options['data']) {
_demo_dump_table_data($fp, $table);
}
}
}
$footer = array();
$footer[] = '';
// Re-enable foreign key checks.
$footer[] = 'SET FOREIGN_KEY_CHECKS = 1;';
// Revert collations for potential subsequent database queries not belonging
// to this module.
// @todo Double-check this behavior according to the results of
// http://drupal.org/node/772678
$footer[] = 'SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT;';
$footer[] = 'SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS;';
$footer[] = 'SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;';
$footer[] = '';
$footer[] = '';
fwrite($fp, implode("\n", $footer));
fclose($fp);
return TRUE;
}
return FALSE;
}