QQ_sqlEXINP.php
Line #0:<?php Session_start();
Line #1:include ("QQ_sqlEXINP.ini");
Line #2:if (isset($_GET[USR_kod])) $dbname=$username.'_'.$_GET[USR_kod];
Line #3:$export=$dbname.'_'. date("Y-m-d_H-i-s").'.sql';
Line #4:
Line #5://header('Content-Type: text/html; charset=utf-8');
Line #6:header("Content-type: application/octet-stream");
Line #7:header("Content-Disposition: attachment; filename=".$export.".gz");
Line #8://header('Content-Type: text/html; charset=latin2');
Line #9:header('Content-Type: text/html; charset=utf-8');
Line #10:
Line #11://echo('EXPORT->'. $hostname.'<hr>');
Line #12://echo('EXPORT->'. $username.'<hr>');
Line #13://echo('EXPORT->'. $password.'<hr>');
Line #14://echo('EXPORT->'. $dbname.'<hr>');
Line #15://echo('EXPORT->'. $_SESSION[Qusr_kod] .'<hr>');
Line #16:
Line #17://*!40101 SET NAMES latin2 */;
Line #18://*!40101 SET CHARACTER SET latin2 */;
Line #19:
Line #20:backup_tables($hostname,$username,$password,$dbname,$export);
Line #21:
Line #22:function backup_tables($host,$user,$pass,$name,$out,$tables = '*')
Line #23:{
Line #24:
Line #25:// echo('EXPORT->'. $name.'<hr>');
Line #26:
Line #27:$return= '
Line #28:/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
Line #29:/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Line #30:/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
Line #31:';
Line #32:
Line #33:// $link = mysql_connect($host,$user,$pass);
Line #34:// mysql_select_db($name,$link);
Line #35:
Line #36://@mysql_query('SET CHARACTER SET utf-8');
Line #37://@mysql_query("SET NAMES 'utf-8'");
Line #38:
Line #39: $link = mysql_connect($host,$user,$pass) or die(mysql_error());
Line #40: mysql_select_db($name,$link) or die(mysql_error());
Line #41: mysql_query("SET NAMES 'utf8'");
Line #42: mysql_query("set character_set_client='utf8'");
Line #43: mysql_query("set character_set_results='utf8'");
Line #44: mysql_query("set collation_connection='utf8'");
Line #45: global $link;
Line #46:
Line #47: //get all of the tables
Line #48: if($tables == '*')
Line #49: {
Line #50: $tables = array();
Line #51: $result = mysql_query('SHOW TABLES');
Line #52: while($row = mysql_fetch_row($result))
Line #53: {
Line #54: $tables[] = $row[0];
Line #55: }
Line #56: }
Line #57: else
Line #58: {
Line #59: $tables = is_array($tables) ? $tables : explode(',',$tables);
Line #60: }
Line #61:
Line #62: //cycle through
Line #63: foreach($tables as $table)
Line #64: {
Line #65: $result = mysql_query('SELECT * FROM '.$table);
Line #66: $num_fields = mysql_num_fields($result);
Line #67:
Line #68://echo($table.'<br>');
Line #69:
Line #70: $return.= 'DROP TABLE '.$table.';';
Line #71: $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
Line #72: $return.= "\n\n".$row2[1].";\n\n";
Line #73:
Line #74: for ($i = 0; $i < $num_fields; $i++)
Line #75: {
Line #76: while($row = mysql_fetch_row($result))
Line #77: {
Line #78: $return.= 'INSERT INTO '.$table.' VALUES(';
Line #79: for($j=0; $j<$num_fields; $j++)
Line #80: {
Line #81: $row[$j] = addslashes($row[$j]);
Line #82: $row[$j] = ereg_replace("\n","\\n",$row[$j]);
Line #83: if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
Line #84: if ($j<($num_fields-1)) { $return.= ','; }
Line #85: }
Line #86: $return.= ");\n";
Line #87: }
Line #88: }
Line #89: $return.="\n\n\n";
Line #90: }
Line #91:
Line #92:
Line #93:$return.= '
Line #94:/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
Line #95:/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
Line #96:/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Line #97:';
Line #98:
Line #99:// echo $return;
Line #100:
Line #101://save file
Line #102:$handle = fopen($out,'w+');
Line #103:fwrite($handle,$return);
Line #104:fclose($handle);
Line #105:
Line #106:
Line #107:// Name of the gz file we are creating
Line #108:$gzfile = $out.".gz";
Line #109:
Line #110:// Open the gz file (w9 is the highest compression)
Line #111:$fp = gzopen ($gzfile, 'w9');
Line #112:// Compress the file
Line #113:gzwrite ($fp, file_get_contents($out));
Line #114:// Close the gz file and we are done
Line #115:gzclose($fp);
Line #116:
Line #117:
Line #118:unlink($out);
Line #119:
Line #120:$myFile = $gzfile;
Line #121:$fh = fopen($myFile, 'r');
Line #122://$theData = fread($fh, 5);
Line #123:$L=filesize($myFile);
Line #124:$theData = fread($fh,$L);
Line #125:fclose($fh);
Line #126://echo(strlen($theData)."<hr>".$L."<hr>".$myFile);
Line #127:
Line #128:echo $theData;
Line #129:
Line #130:unlink($myFile);
Line #131:
Line #132:}
Line #133:?>
Line #134: