Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:22:25+00:00 2026-06-07T22:22:25+00:00

I want to setup a button in my content management system where I can

  • 0

I want to setup a button in my content management system where I can save a backup sql file for the table shown on a particular page. I just want it to download the SQL file to my computer if this is possible. I also wanted to know if it’s possible to do the same thing but export as an excel file of the table data.

If it’s easier to just do a backup of the whole database I’d settle for that, I just need to know if it’s possible and what it is I’m looking for to build the script.

Hopefully this makes sense, I’m struggling to know what I need to look for as I don’t know if it’s actually possible. I’m coding in php.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:22:28+00:00Added an answer on June 7, 2026 at 10:22 pm

    Here’s a small page enabling you to :

    • check the tables you want
    • download them
    • or write them on disk (server side)

    BUT

    you shouldn’t do that if you care about security.

    If you want to do this kind of manipulation I recommend you to use phpMyAdmin instead.

    And if you just want to do automatic backups without downloading, you’d better use cron and the mysqldump command. Cron is configured on many servers to do a backup every night.

    Look at this :

    http://www.comentum.com/mysqldump-cron.html

    http://www.noupe.com/how-tos/10-ways-to-automatically-manually-backup-mysql-database.html

    Well. Here’s the PHP page :

    <?
    
    $db_base="set_your_base";
    $db=mysql_connect("xxxx","xxxx","xxxx")
    or die ("unable to connect");
    $select_base=mysql_selectdb($db_base,$db);
    
    
    function get_para_value($name, $default_value) {
        global $HTTP_GET_VARS, $HTTP_POST_VARS, $_GET, $_POST;
        if( isset($_GET[$name])) {
            return $_GET[$name];
        }
        if( isset($_POST[$name])) {
            return $_POST[$name];
        }
        return $default_value;
    }
    
    
    $action=get_para_value('action', 'ask');
    
    if ($action=='ask') {
        ?>
        <html>
        <body>
        <SCRIPT LANGUAGE="JavaScript">
        var checkflag = "false";
        function check(form) {
            var objCheckBoxes = form.elements;
            if (checkflag == "false") {
                for (i = 0; i < objCheckBoxes.length; i++) {
                    objCheckBoxes[i].checked = true;
                }
                checkflag = "true";
                return "Uncheck all";
            } else {
                for (i = 0; i < objCheckBoxes.length; i++) {
                    objCheckBoxes[i].checked = false;
                }
                checkflag = "false";
                return "Check all";
            }
        }
        </script>
    
        <center>
    
        <form name=dump_form action=dump_dys.php method="post" enctype="multipart/form-data" accept-charset="utf-8">
        <br>
        Choose the tables you want:
        <br>
        <br>
        <input type=button value="Check all" onClick="this.value=check(this.form)">
        <br>
        <br>
        <table>
        <?php
        $sql_tables = "SHOW TABLES";
        $req_tables = mysql_query($sql_tables);
        while (list($table) = mysql_fetch_row($req_tables)) {
            echo "<tr><td><input type=checkbox name=".$table."> ".$table."</td></tr>";
        }
        ?>
        </table>
        <input type=hidden name=action value=dump>
        <br>
        <input type=button value="Download" onClick="this.form.action.value='dump';this.form.submit();">
        &nbsp; <input type=button value="Write on server" onClick="this.form.action.value='dump_to_disk';this.form.submit();">
        </form>
        </center>
        </body>
        </html>
        <?php
    } else if ($action=='dump') {
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment;filename=\"$db_base.sql\"");
        header("Content-Transfer-Encoding: binary");
        echo "--\n";
        echo "-- Dump of database $db_base\n";
        echo "--\n";
        $sql_tables = "SHOW TABLES";
        $req_tables = mysql_query($sql_tables);
        while (list($table) = mysql_fetch_row($req_tables)) {
            if (get_para_value($table,'no')=='no') continue;
            echo "\n--\n-- Table $table\n\n";
            echo "DROP TABLE IF EXISTS $table;\n";
            $sql_create_table = "SHOW CREATE TABLE $table";
            $req_create_table = mysql_query($sql_create_table);
            $create_table = mysql_fetch_array($req_create_table);
            echo $create_table[1].";\n";
            echo "\n--\n-- Filling de $table\n\n";
            $sql_fill_table = "SELECT * FROM $table";
            $req_fill_table = mysql_query($sql_fill_table);
            while ($row = mysql_fetch_assoc($req_fill_table)) {
            $line_insert = "INSERT INTO $table (";
            $l_value = ") VALUES (";
            foreach ($row as $field => $value) {
                $line_insert .= "`$field`, ";
                $l_value .= "'".mysql_real_escape_string($value)."', ";
            }
            $line_insert = substr($line_insert, 0, -2);
            $l_value = substr($l_value, 0, -2);
            echo $line_insert.$l_value.");\n";
           }
        }
    
        echo "--\n";
        echo "-- Dump of base $db_base finished )\n";
        echo "--\n";
    } else if ($action=='dump_to_disk') {
        $file = fopen($db_base.".sql", 'w') or die('bug!');
        fwrite($file, "--\n");
        fwrite($file,  "-- Dump of the base $db_base\n");
        fwrite($file,  "--\n");
        $sql_tables = "SHOW TABLES";
        $req_tables = mysql_query($sql_tables);
        while (list($table) = mysql_fetch_row($req_tables)) {
            if (get_para_value($table,'no')=='no') continue;
            fwrite($file,  "\n--\n-- Table $table\n\n");
            fwrite($file,  "DROP TABLE IF EXISTS $table;\n");
            $sql_create_table = "SHOW CREATE TABLE $table";
            $req_create_table = mysql_query($sql_create_table);
            $create_table = mysql_fetch_array($req_create_table);
            fwrite($file,  $create_table[1].";\n");
            fwrite($file,  "\n--\n-- Remplissage de $table\n\n");
            $sql_fill_table = "SELECT * FROM $table";
            $req_fill_table = mysql_query($sql_fill_table);
            while ($row = mysql_fetch_assoc($req_fill_table)) {
            $line_insert = "INSERT INTO $table (";
            $l_value = ") VALUES (";
            foreach ($row as $field => $value) {
                $line_insert .= "`$field`, ";
                $l_value .= "'".mysql_real_escape_string($value)."', ";
            }
            $line_insert = substr($line_insert, 0, -2);
            $l_value = substr($l_value, 0, -2);
            fwrite($file,  $line_insert.$l_value.");\n");
           }
        }
        fwrite($file, "--\n");
        fwrite($file, "-- Dump of base $db_base finished (not even a crash!)\n");
        fwrite($file, "--\n");
        fclose($file);
        echo "dump done";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to setup a Method dispatch table and I am wondering if it
I want to setup a route so that if the user goes to http://mysite.com/page.html
I am looking for some help autosaving tinyMCE. I want to save the content
I have an iframe setup within a page and basically want to know whether
I want to load content stored in a file, into the fields of a
I want to add a tab with content from a page I made to
I want to setup a video on demand server which support Http protocol. It
I want to setup the TFS to build both Debug and Release versions of
I want to setup my test/dev environment for Alfresco on Rackspace cloud, since I'm
I want a setup like this: +- /ApplicationFolder -- App.exe -- Core.dll -- AnotherShared.dll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.