MySQL Database Dump with all tables and data
Results 1 to 1 of 1

Thread: MySQL Database Dump with all tables and data

  1. #1
    Join Date
    Jun 2005

    MySQL Database Dump with all tables and data

    Sometimes you want to have a quick check of your database.

    This simple script will give a quick and dirty way to do a check.
    PHPmyadmin is of course a proper alternative.
    But the way I show here is quicker and very simple.

    My script uses MySQLi for connection.
    To run you need to configure MySQLi = host, user, pass.
    After this you are ready to run.

    You submit database name and click submit.
    After this you will see all tables and data in your selected database.
    If that mysql database does not exist, you will get an error.

    PHP Code:
    <!DOCTYPE html>
    <meta charset="UTF-8">
    <title>Dump Database</title>
        body {background: #c7c7c7; font-size: 12px}
        table {background: #ffffee; border-collapse: collapse}
        th, td{border: 1px solid black}

    if (isset($_POST['database'])) {

    // MySQLi configure
    $host 'localhost';
    $user 'root';
    $pass '';
    // End config

    $base $_POST['database'];
    $db = new mysqli($host$user$pass);
        if (
    'Connect Error('.$db->connect_errno.')'.$db->connect_error);
        if (
    $db->select_db($base)) {
    $result $db->query("SHOW TABLES FROM $base");
    $alltables = new stdClass;
    $i 0;
    $table $result->fetch_object()) {
    $alltables->$i $table->{"Tables_in_$base"};

    '<h3>Database: '.$base.'</h3>';

    $alltables as $table) {

    $result $db->query("SHOW COLUMNS FROM $table");
    $allcolumns = new stdClass;
    $i 0;
    $column $result->fetch_object()) {
    $allcolumns->$i $column->Field;
    $numcol count((array)$allcolumns);
    '<tr><th colspan="'.$numcol.'">'.$table.'</th></tr>';
    $allcolumns as $col)

    $result $db->query("SELECT * FROM $table");
    $row $result->fetch_object()) {
    $row as $field)
        } else {
    '<i>'.$base.'</i> database does not exist.<br><br>');

    <form method="post" accept-charset="UTF-8">
    MySQL database name:<br>
    <input type="text" name="database"><br>
    <input type="submit"></form>
    Apache-2.4.28 (Win64) / PHP-7.1.10 / MySQL-5.7.19 / phpMyAdmin-4.7.4

  2. #2
    Junior Member
    Join Date
    Feb 2018
    That's very useful! Thanks for sharing this thread, guys! I'll try to follow your directions, to have a quick check of my database.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts