$row = mysql_fetch_array($result);
// add comma's except for last one
if ($row)
echo ",\n";
}
//
// Get any Indexed fields from the database...
//
$result = mysql_query("SHOW KEYS FROM $tablename");
while($row =
mysql_fetch_array($result)) {
$kname = $row['Key_name'];
if(($kname != 'PRIMARY') && ($row['Non_unique'] == 0))
$kname = "UNIQUE|$kname";
if(($kname != 'PRIMARY') && ($row['Index_type'] == 'FULLTEXT'))
$kname = "FULLTEXT|$kname";
if(!is_array($index[$kname]))
$index[$kname] = array();
$index[$kname][] = $row['Column_name'];
}
while(list($x, $columns) = @each($index)) {
echo ", \n";
if($x == 'PRIMARY')
echo ' PRIMARY KEY (' . implode($columns, ', ') . ')';
elseif (substr($x,0,6) == 'UNIQUE')
echo ' UNIQUE KEY ' . substr($x,7) . ' (' . implode($columns, ', ') . ')';
elseif (substr($x,0,8) == 'FULLTEXT')
echo ' FULLTEXT KEY ' . substr($x,9) . ' (' . implode($columns, ', ') . ')';
elseif (($x == 'ibody') || ($x == 'cbody')) // karma 2004-05-30 quick and dirty fix. fulltext keys were not in SQL correctly.
echo ' FULLTEXT KEY ' . substr($x,9) . ' (' . implode($columns, ', ') . ')';
else
echo " KEY $x (" . implode($columns, ', ') . ')';
}
echo "\n);\n\n";
}
function _backup_dump_contents($tablename) {
//
// Grab the data from the table.
//
$result = mysql_query("SELECT * FROM $tablename");
if(mysql_numrows($result) > 0)
echo "\n#\n# Table Data for $tablename\n#\n";
//
// Loop through the resulting rows and build the sql statement.
//
while ($row = mysql_fetch_array($result))
{
$tablename_list = '(';
$num_fields = mysql_num_fields($result);
//
// Grab the list of field names.
//
for ($j = 0; $j < $num_fields; $j++)
$tablename_list .= mysql_field_name($result, $j) . ', ';
//
// Get rid of the last comma
//
$tablename_list = ereg_replace(', $', '', $tablename_list);
$tablename_list .= ')';
// Start building the SQL statement.
echo "INSERT INTO $tablename $tablename_list VALUES(";
// Loop through the rows and fill in data for each column
for ($j = 0; $j < $num_fields; $j++) {
if(!isset($row[$j])) {
// no data for column
echo ' NULL';
} elseif ($row[$j] != '') {
// data
echo " '" . addslashes($row[$j]) . "'";
} else {
// empty column (!= no data!)
echo "''";
}
// only add comma when not last column
if ($j != ($num_fields - 1))
echo ",";
}
echo ");\n";
}
echo "\n";
}
// copied from phpBB
function gzip_PrintFourChars($Val)
{
for ($i = 0; $i < 4; $i ++)
{
$return .= chr($Val % 256);
$Val = floor($Val / 256);
}
return $return;
}
function do_restore() {
$uploadInfo = postFileInfo('backup_file');
// first of all: get uploaded file:
if (empty($uploadInfo['name']))
return 'No file uploaded';
if (!is_uploaded_file($uploadInfo['tmp_name']))
return 'No file uploaded';
$backup_file_name = $uploadInfo['name'];
$backup_file_tmpname = $uploadInfo['tmp_name'];
$backup_file_type = $uploadInfo['type'];
if (!file_exists($backup_file_tmpname))
return 'File Upload Error';
if (!preg_match("/^(text\/[a-zA-Z]+)|(application\/(x\-)?gzip(\-compressed)?)|(application\/octet-stream)$/is", $backup_file_type) )
return 'The uploaded file is not of the correct type';
if (preg_match("/\.gz/is",$backup_file_name))
$gzip = 1;
else
$gzip = 0;
if (!extension_loaded("zlib") && $gzip)
return "Cann