<?
$db_host='localhost';
$db_name='nazwa-bazy';
$db_pass='haslo';
$db_user='user';
$site_name='nazwa strony';
$aadres;='adres strony';
$crlf="n";
$strNoTablesFound = "Brak tabel w bazie danych.";
$strHost = "Host";
$strDatabase = "Baza danych ";
$strTableStructure = "Struktura tabeli dla";
$strDumpingData = "Zawartosc tabeli";
$strError = "blad";
$strSQLQuery = "SQL";
$strMySQLSaid = "MySQL : ";
$strBack = "Wstecz";
$strFileName = "Kopia bazy";
$strName = "Baza danych";
$strDone = "Z dnia";
$strat = "";
$strby = "by";
$date_jour = date ("m-d-Y");
header("Content-disposition: filename=$strFileName $db_name $date_jour.sql"); header("Content-type: application/octetstream");
// doing some DOS-CRLF magic...
$client = getenv("HTTP_USER_AGENT"); if(ereg('[^(]*((.*))[^)]*',$client,$regs)) {
$os = $regs[1];
// this looks better under WinX
$crlf="rn";
}
function my_handler($sql_insert)
{
echo "$sql_insert;$crlf"; }
// Get the content of $table as a series of INSERT statements.
// After every row, a custom callback function $handler gets called.
// $handler must accept one parameter ($sql_insert);
function get_table_content($db, $table, $handler)
{
$i = 0;
{
// set_time_limit(60); // HaRa
$table_list = "(";
for($j=0; $j<mysql_num_fields($result);$j++)
$table_list = substr($table_list,0
,-2
); $table_list .= ")";
if(isset($GLOBALS["showcolumns"])) $schema_insert = "INSERT INTO $table $table_list VALUES (";
else
$schema_insert = "INSERT INTO $table VALUES (";
for($j=0; $j<mysql_num_fields($result);$j++)
{
$schema_insert .= " NULL,";
elseif($row[$j] != "")
else
$schema_insert .= " '',";
}
$schema_insert .= ")";
$handler(trim($schema_insert)); $i++;
}
return (true);
}
// Return $table's CREATE definition
// Returns a string containing the CREATE statement on success
function get_table_def($db, $table, $crlf)
{
$schema_create = "";
//$schema_create .= "DROP TABLE IF EXISTS $table;$crlf";
$schema_create .= "CREATE TABLE $table ($crlf";
$result = mysql_db_query($db, "SHOW FIELDS FROM $table") or mysql_die
(); {
$schema_create .= " $row[Field] $row[Type]";
if(isset($row["Default"]) && (!empty($row["Default"]) || $row["Default"] == "0")) $schema_create .= " DEFAULT '$row[Default]'";
if($row["Null"] != "YES")
$schema_create .= " NOT NULL";
if($row["Extra"] != "")
$schema_create .= " $row[Extra]";
$schema_create .= ",$crlf";
}
$schema_create = ereg_replace(",".$crlf."$", "", $schema_create); $result = mysql_db_query($db, "SHOW KEYS FROM $table") or mysql_die
(); {
$kname=$row['Key_name'];
if(($kname != "PRIMARY") && ($row['Non_unique'] == 0))
$kname="UNIQUE|$kname";
if(!isset($index[$kname])) $index[$kname] = array(); $index[$kname][] = $row['Column_name'];
}
while(list
($x, $columns) = @each($index)) {
$schema_create .= ",$crlf";
if($x == "PRIMARY")
$schema_create .= " PRIMARY KEY (" . implode($columns, ", ") . ")"; elseif (substr($x,0,6) == "UNIQUE") $schema_create .= " UNIQUE ".substr($x,7)." (" . implode($columns, ", ") . ")"; else
$schema_create .= " KEY $x (" . implode($columns, ", ") . ")"; }
$schema_create .= "$crlf)";
}
function mysql_die($error = "")
{
echo "<b> $strError </b><p>"; {
echo "$strSQLQuery: <pre>$sql_query</pre><p>"; }
else
echo $strMySQLSaid.$error; echo "<br><a href="java script
:history
.go
(-1)">$strBack</a>"; }
global $db_host, $db_name, $db_pass, $db_user, $site_name, $aadres;
if($num_tables == 0)
{
}
else
{
$i = 0;
$heure_jour = date ("H:i"); print "# ========================================================$crlf"; print "# $strName : $db_name$crlf"; print "# $strDone $date_jour $strat $heure_jour$crlf"; print "# $site_name ($aadres)$crlf"; print "# ========================================================$crlf";
while($i < $num_tables)
{
print "# --------------------------------------------------------$crlf"; print "# $strTableStructure '$table'$crlf";
echo get_table_def
($db_name, $table, $crlf).";$crlf$crlf";
print "# $strDumpingData '$table'$crlf";
get_table_content($db_name, $table, "my_handler");
$i++;
}
}
?>
taki mały skrypcik

(jest z phpnuke przerobiony)