www.webdeveloper.com
+ Reply to Thread
Results 1 to 3 of 3

Thread: Show SQL Export

  1. #1
    Join Date
    Oct 2005
    Posts
    593

    Show SQL Export

    Hi,

    Is it possible to have a script that can create an SQL Export for a whole table / database and shows it to you on screen without having to login to PHPMyAdmin?

    Scott
    At last.. I can make my text bold

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,722
    PHP Code:
    <?php
    $mysql 
    mysql_connect('localhost','root','') or die ('Could not connect to MySQL: ' mysql_error());
    mysql_select_db('test') or die ('Could not select the database: ' mysql_error());

    $tables = array('table_1''table _2''etc');

    $content '';

    foreach(
    $tables as $table){
        
    $content .= print_table($table);
    }

    function 
    print_table($tablename)
    {
        
    $query "SELECT * FROM $tablename";
        
    $query_result mysql_query($query) or die (mysql_error());
        if(
    mysql_num_rows($query_result) > 0)
        {
            
    $return '<table class="mysql_table" border="1" cellspacing="0" cellpadding="6">'."\n".
                      
    '<caption>Table name: "'.$tablename.'"</caption>'."\n";
            
    $first_time true;
            while(
    $row mysql_fetch_assoc($query_result))
            {
                if(
    $first_time)
                {
                    
    $first_time false;
                    
    $headings array_keys($row);
                    
    $return .= '<tr>';
                    foreach(
    $headings as $heading)
                    {
                        
    $return .= '<th>'.$heading.'</th>';
                    }
                    
    $return .= '</tr>'."\n";
                }
                
    $return .=  '<tr>';
                foreach(
    $headings as $heading)
                {
                    
    $return .= '<td>';
                    
    $return .= ($row[$heading]) ? $row[$heading] : '&nbsp;';
                    
    $return .=  '</td>';
                }
                
    $return .=  '</tr>'."\n";
            }
            
    $return .=  '</table>'."\n";
            return 
    $return;
        }
        else
        {
            return 
    'The table "'.$tablename.'" does not have anything in it yet<br>'."\n";
        }
    }

    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">
    <head>

    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        
    <style type="text/css">
    .mysql_table caption{
        color: #008;
        font-size: 9pt;
        font-family:  verdana, sans-serif;
        margin: 0 0 5px 0;
        white-space: nowrap;
    }

    .mysql_table th{
        color: #008;
        font-size: 8pt;
        font-family:  verdana, sans-serif;
        
        white-space: nowrap;
    }

    .mysql_table td{
        color: #008;
        font-size: 8pt;
        font-family:  verdana, sans-serif;
        white-space: nowrap;
    }
    </style>

    <title>View tables</title>
      
    </head>

    <body>

    <?php echo $content ?>

    </body>
    </html>

  3. #3
    Join Date
    Oct 2005
    Posts
    593
    Thanks for that bokeh, thats not exactly what i was looking for but is handy!

    Im trying to create a DB backup script from my site.. So when i click a button it will export the whole of my DB to a txt file which i can save to my desktop bassically.. So when i go into phpmyadmin, i can copy that text and it will reload the database! I.E the SQL Export you get when clicking Export in PHPMyAdmin
    At last.. I can make my text bold

Thread Information

Users Browsing this Thread

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

     

Bookmarks

Posting Permissions

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



Recent Articles