function formatrow ( $res, $num_f, $id_row,$table)
{
$k = 0;
$ret = '';
$str="insert into $table values(";
while($k<$num_f)
{
$Mod=mysql_result($res,$id_row,$k);
$modi="\"".$Mod."\",";
$ret = "$ret$modi";
$k = $k +1;
}
$trimed=trim("$str$ret",",");
return ("$trimed");
}
function get_table_def($db, $table, $crlf)
{
global $drop;
$schema_create = "";
if(!empty($drop))
$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();
while($row = mysql_fetch_array($result))
{
$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();
while($row = mysql_fetch_array($result))
{
$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)";
return (stripslashes($schema_create));
}
$client = getenv("HTTP_USER_AGENT");
if(ereg('[^(]*\((.*)\)[^)]*',$client,$regs))
{
$os = $regs[1];
// this looks better under WinX
if (eregi("Win",$os))
$crlf="\r\n";
}
include('confige.php');
if ($r1=='str')
{
if ($ch1=='send')
{
header("Content-disposition: filename=$db.sql");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
mysql_select_db("$db");
$tables = mysql_list_tables("$db");
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table = mysql_tablename($tables, $i);
$TR= get_table_def($db,$table, $crlf);
print "$TR; $crlf$crlf";
$i++;
}
}
else
{
print"<html>
<head>
<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=windows-1251\">
<link rel=\"StyleSheet\" type=\"text/css\" href=\"css\style.css\">
</head>";
$crlf="<br>";
print"<center><h2>Dump for database $db</h2></center>";
$tables = mysql_list_tables("$db");
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table = mysql_tablename($tables, $i);
$TR= get_table_def($db,$table, $crlf);
print "$TR; $crlf$crlf";
$i++;
}
}
}
if ($r1=="strdata")
{
if($ch1=='send')
{
//------------------------------------------------------------------------------
header("Content-disposition: filename=$db.sql");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
mysql_select_db("$db");
$tables = mysql_list_tables("$db");
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table = mysql_tablename($tables, $i);
$TR= get_table_def($db,$table, $crlf);
print "$TR; $crlf$crlf";
$i++;
}
$t=0;
while($t<$num_tables)
{
$table = mysql_tablename($tables,$t);
$query=("select * from $table");
$result=mysql_query($query);
$fields = mysql_num_fields($result);
$row=mysql_numrows($result);
$y=0;
while($y <$row )
{
$s[$y] = formatrow($result,$fields,$y,$table);
print" $s[$y]);$crlf";
$y++;
}
$t++;
}
}
//-----------------------------------------------------------------------------
elseif($ch1!=='send')
{
print"<html>
<head>
<link rel=\"StyleSheet\" type=\"text/css\" href=\"css\style.css\">
</head>";
print"<center><h2>Dump for database $db</h2></center>";
$crlf="<br>";
mysql_select_db("$db");
$tables = mysql_list_tables("$db");
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table = mysql_tablename($tables, $i);
$TR= get_table_def($db,$table, $crlf);
print "$TR; $crlf$crlf";
$i++;
}
$t=0;
while($t<$num_tables)
{
$table = mysql_tablename($tables,$t);
$query=("select * from $table");
$result=mysql_query($query);
$fields = mysql_num_fields($result);
$row=mysql_numrows($result);
$y=0;
while($y <$row )
{
$s[$y] = formatrow($result,$fields,$y,$table);
print" $s[$y]);$crlf";
$y++;
}
$t++;
}
}
}
mysql_close();