<? global $vis_language;
header('Content-type: application/zip');
header("Content-Disposition: attachment; filename=DbBackup.sql");
$level=9;
$html='################################## Database Backup #############################'."\n".'CREATE DATABASE IF NOT EXISTS `'.$dbname.'`;'."\n";
echo $html;
$count=count($db);
for($i=0;$i<$count;$i++) {
    set_time_limit(600);
    $html="\n\n".'#=======================================# Table Name: '.$db[$i]['Name'].' #=======================================#'."\n";
    echo $html;
    $rowDetail=$object->create_tab($db[$i]['Name'],0);
    $fldDetail=$object->create_tab($db[$i]['Name'],1);
    $tabEntry=$object->create_tab($db[$i]['Name'],2);
    $cnt=count($fldDetail);
    $html="\n".'DROP TABLE IF EXISTS `'.$db[$i]['Name'].'`;'."\n".$rowDetail[0]['Create Table'].';'."\n";
    echo $html;
    if(count($tabEntry)!=0) {
        insert_table($db[$i]['Name'], $tabEntry, $cnt, $object);
    }
}
function insert_table($tbName, $tabEntry, $cnt, $object) {
    if(!$tabEntry) return '';
    $tabEntryr=$object->database->fetch_result($tabEntry, true);
    while($tabEntryr && $tabEntryr!=-1) {
        $str = 'INSERT INTO `'.$tbName.'` VALUES ';
        $str .= '(';
        for($i=0;$i<$cnt;$i++) {
            $str .= '"'.addslashes($tabEntryr[$i]).'",';
        }
        $str = substr($str, 0, -1);
        $str .= ');'."\n";
        echo $str;
        $tabEntryr=$object->database->fetch_result($tabEntry, true);
    }
}?>