Ejemplo n.º 1
0
function sqlbackup($ip, $sql, $username, $password)
{
    global $meurl;
    if (class_exists('ZipArchive')) {
        maintop("MySQL备份");
        $database = $sql;
        //数据库名
        $options = array('hostname' => $ip, 'charset' => 'utf8', 'filename' => $database . '.sql', 'username' => $username, 'password' => $password);
        mysql_connect($options['hostname'], $options['username'], $options['password']) or die("不能连接数据库!");
        mysql_select_db($database) or die("数据库名称错误!");
        mysql_query("SET NAMES '{$options['charset']}'");
        $tables = list_tables($database);
        $filename = sprintf($options['filename'], $database);
        $fp = fopen($filename, 'w');
        foreach ($tables as $table) {
            dump_table($table, $fp);
        }
        fclose($fp);
        //压缩sql文件
        if (file_exists('mysql.zip')) {
            unlink('mysql.zip');
        }
        $file_name = $options['filename'];
        $zip = new ZipArchive();
        $res = $zip->open('mysql.zip', ZipArchive::CREATE);
        if ($res === TRUE) {
            $zip->addfile($file_name);
            $zip->close();
            //删除服务器上的sql文件
            unlink($file_name);
            echo '<div class="box">数据库导出并压缩完成!' . " <a href=\"" . $meurl . "?op=home&folder=" . $_SESSION['folder'] . "\">返回上次浏览的文件夹</a></div>\n";
        } else {
            printerror('无法压缩文件!');
        }
        exit;
        mainbottom();
    } else {
        printerror('此服务器上的PHP不支持ZipArchive,无法压缩文件!');
    }
}
Ejemplo n.º 2
0
function dump_all($data = false)
{
    global $db_name;
    ob_cleanup();
    define('DEBUG_CONSOLE_HIDE', 1);
    set_time_limit(0);
    $tables = list_tables();
    $table_filter = get('table_filter');
    $tables = table_filter($tables, $table_filter);
    header("Cache-control: private");
    header("Content-type: application/octet-stream");
    header('Content-Disposition: attachment; filename=' . date('Ymd') . '_' . $db_name . '.sql');
    foreach ($tables as $key => $table) {
        table_structure($table);
        if ($data) {
            table_data($table);
        }
        flush();
    }
    exit;
}
Ejemplo n.º 3
0
function dump_all($data = false)
{
    // @dump
    // @structure
    // @data
    GET("table_filter", "string");
    global $db_driver, $db_server, $db_name;
    ob_cleanup();
    define('DEBUG_CONSOLE_HIDE', 1);
    set_time_limit(0);
    $tables = list_tables();
    $table_filter = $_GET["table_filter"];
    $tables = table_filter($tables, $table_filter);
    header("Cache-control: private");
    header("Content-type: application/octet-stream");
    header('Content-Disposition: attachment; filename=' . $db_name . '.sql');
    echo "--\n";
    if ($data) {
        echo "-- Dump type: DATA & STRUCTURE\n";
    } else {
        echo "-- Dump type: STRUCTURE ONLY\n";
    }
    if ("sqlite" == $db_driver) {
        echo "-- Database file: {$db_server}\n";
    } else {
        echo "-- Database: {$db_name}\n";
    }
    $date = date("Y-m-d");
    echo "-- Exported on: {$date}\n";
    $version = DBKISS_VERSION;
    echo "-- Powered by: DBKiss (http://www.gosu.pl/dbkiss/)\n";
    echo "--\n\n";
    foreach ($tables as $key => $table) {
        echo "-- TABLE: \"{$table}\"\n\n";
        table_structure($table);
        if ($data) {
            echo "-- INSERTS for: \"{$table}\"\n\n";
            table_data($table);
        }
        flush();
    }
    unset($table);
    $views = list_tables(true);
    foreach ($views as $key => $view) {
        echo "-- VIEW: \"{$view}\"\n\n";
        table_structure($view, "view");
        flush();
    }
    echo "--\n";
    echo "-- END OF DUMP\n";
    echo "--\n";
    exit;
}
Ejemplo n.º 4
0
function has_tiki_db_20($dbTiki)
{
    return in_array('tiki_pages_translation_bits', list_tables($dbTiki));
}
Ejemplo n.º 5
0
function process_tables($db1, $db2)
{
    global $options;
    $tables1 = list_tables($db1);
    $tables2 = list_tables($db2);
    create_tables($db1, $tables1, $tables2);
    if ($options->drop_tables) {
        drop_tables($tables1, $tables2);
    }
    alter_tables($tables1, $tables2);
    alter_tables_columns($db1, $db2);
    process_indexes($tables1, $tables2, $db1, $db2);
}
function sqlbackup($ip, $sql, $username, $password)
{
    global $meurl;
    if (class_exists('ZipArchive')) {
        maintop("MySQL Backup");
        $database = $sql;
        $options = array('hostname' => $ip, 'charset' => 'utf8', 'filename' => $database . '.sql', 'username' => $username, 'password' => $password);
        mysql_connect($options['hostname'], $options['username'], $options['password']) or die("Fail to connect DB!");
        mysql_select_db($database) or die("Database name error!");
        mysql_query("SET NAMES '{$options['charset']}'");
        $tables = list_tables($database);
        $filename = sprintf($options['filename'], $database);
        $fp = fopen($filename, 'w');
        foreach ($tables as $table) {
            dump_table($table, $fp);
        }
        fclose($fp);
        if (file_exists('mysql.zip')) {
            unlink('mysql.zip');
        }
        $file_name = $options['filename'];
        $zip = new ZipArchive();
        $res = $zip->open('mysql.zip', ZipArchive::CREATE);
        if ($res === TRUE) {
            $zip->addfile($file_name);
            $zip->close();
            unlink($file_name);
            echo 'Database Export and compression jobs done!' . " <a href=\"" . $meurl . "?op=root&folder=" . $_SESSION['folder'] . "\">Back</a>\n";
        } else {
            printerror('Unable to compress files!');
        }
        exit;
        mainbottom();
    } else {
        printerror('PHP on this server does not support ZipArchive, unable to extract the zip files!');
    }
}