NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   MySQL Dump Script (http://www.namepros.com/code/244453-mysql-dump-script.html)

Barrucadu 10-05-2006 10:47 AM

MySQL Dump Script
 
This script returns the table structures of every table in every database.
To use just edit the variables at the top of the script.

If you find any bugs tell me. And yes, I will make it dump table contents sometime, lol

PHP Code:
<?php
set_time_limit
(0);
$db['host'] = '';
$db['user'] = '';
$db['pass'] = '';

function
error($error_msg){
    die(
'<script>
    alert("An error occured!");
    alert("'
.$error_msg.'");
    </script>'
);
}

mysql_connect($db['host'],$db['user'],$db['pass'])or error(mysql_error());

$databases = mysql_query('SHOW DATABASES;')or error(mysql_error());
$i=0;
while(
$i<mysql_num_rows($databases)){
    
mysql_select_db(mysql_result($databases,$i));
    
$tables=mysql_query('SHOW TABLES;')or error(mysql_error());
    echo
'CREATE DATABASE `'.mysql_result($databases,$i).'`<br />';
    
$i2=0;
    while(
$i2<mysql_num_rows($tables)){
        
$fields=mysql_query('DESCRIBE `'.mysql_result($tables,$i2).'`;')or error(mysql_error());
        echo
'CREATE TABLE `'.mysql_result($tables,$i2).'`(<br />';
        
$i3=0;
        while(
$i3<mysql_num_rows($fields)){
            echo
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`'.mysql_result($fields,$i3,'field').'` '.mysql_result($fields,$i3,'type');
            if(
mysql_result($fields,$i3,'null') != 'NULL'){
                echo
' NOT NULL';
                if(
mysql_result($fields,$i3,'default') != ''){
                    echo
' DEFAULT \''.mysql_result($fields,$i3,'default').'\'';
                }
            }else{
                echo
' DEFAULT NULL';
            }
            
            echo
'<br />';
            
$i3++;
        }
        echo
')<br /><br />';
        
$i2++;
    }
    
$i++;
}
?>


All times are GMT -7. The time now is 03:17 PM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0