<commit_before><?php require_once '_header.mandatory.php';

$fmw->checkOperator();

/* Backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
	
	$link = mysql_connect($host,$user,$pass);
	mysql_select_db($name,$link);
	
	//get all of the tables
	if($tables == '*')
	{
		$tables = array();
		$result = mysql_query('SHOW TABLES');
		while($row = mysql_fetch_row($result))
		{
			$tables[] = $row[0];
		}
	}
	else
	{
		$tables = is_array($tables) ? $tables : explode(',',$tables);
	}
	
    // Deleting tables in the inverse order
    $tables_reversed = array_reverse($tables);
	foreach($tables_reversed as $table)
	{
		$return.= 'DROP TABLE IF EXISTS '.$table.";\n";
	}
    
	// Creating tables and its content
	foreach($tables as $table)
	{
		$result = mysql_query('SELECT * FROM '.$table);
		$num_fields = mysql_num_fields($result);
		
		$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
		$return.= "\n\n".$row2[1].";\n\n";
		
		for ($i = 0; $i < $num_fields; $i++) 
		{
			while($row = mysql_fetch_row($result))
			{
				$return.= 'INSERT INTO '.$table.' VALUES(';
				for($j=0; $j<$num_fields; $j++) 
				{
					$row[$j] = addslashes($row[$j]);
					$row[$j] = str_replace("\n","\\n",$row[$j]);
					if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= 'NULL'; }
					if ($j<($num_fields-1)) { $return.= ','; }
				}
				$return.= ");\n";
			}
		}
		$return.="\n\n\n";
	}

    return $return;
}

// Name of files
$date_string = date("Y-m-d_-_H_i_s");
$sql_filename = 'db-easybiblio-'.$data_string.'.sql';
$zip_filename = 'backup/db-easybiblio-'.$date_string.'.zip';


// Create backup
$files_to_backup = "tb_category,tb_language,tb_person,tb_type,tb_book,tb_lend";
$db_backup = backup_tables($fmw->config->server, $fmw->config->username, $fmw->config->password, $fmw->config->database_name, $files_to_backup);
<commit_msg>backup.php: Make sure .sql file has same name as .zip file<commit_after><?php require_once '_header.mandatory.php';

$fmw->checkOperator();

/* Backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
	
	$link = mysql_connect($host,$user,$pass);
	mysql_select_db($name,$link);
	
	//get all of the tables
	if($tables == '*')
	{
		$tables = array();
		$result = mysql_query('SHOW TABLES');
		while($row = mysql_fetch_row($result))
		{
			$tables[] = $row[0];
		}
	}
	else
	{
		$tables = is_array($tables) ? $tables : explode(',',$tables);
	}
	
    // Deleting tables in the inverse order
    $tables_reversed = array_reverse($tables);
	foreach($tables_reversed as $table)
	{
		$return.= 'DROP TABLE IF EXISTS '.$table.";\n";
	}
    
	// Creating tables and its content
	foreach($tables as $table)
	{
		$result = mysql_query('SELECT * FROM '.$table);
		$num_fields = mysql_num_fields($result);
		
		$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
		$return.= "\n\n".$row2[1].";\n\n";
		
		for ($i = 0; $i < $num_fields; $i++) 
		{
			while($row = mysql_fetch_row($result))
			{
				$return.= 'INSERT INTO '.$table.' VALUES(';
				for($j=0; $j<$num_fields; $j++) 
				{
					$row[$j] = addslashes($row[$j]);
					$row[$j] = str_replace("\n","\\n",$row[$j]);
					if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= 'NULL'; }
					if ($j<($num_fields-1)) { $return.= ','; }
				}
				$return.= ");\n";
			}
		}
		$return.="\n\n\n";
	}

    return $return;
}

// Name of files
$date_string = date("Y-m-d_-_H_i_s");
$sql_filename = 'db-easybiblio-'.$date_string.'.sql';
$zip_filename = 'backup/db-easybiblio-'.$date_string.'.zip';


// Create backup
$files_to_backup = "tb_category,tb_language,tb_person,tb_type,tb_book,tb_lend";
$db_backup = backup_tables($fmw->config->server, $fmw->config->username, $fmw->config->password, $fmw->config->database_name, $files_to_backup);

{'fraction_non_alphanumeric': 0.22251104756953471, 'fraction_numerical': 0.00363919937613725, 'mean_word_length': 3.8463476070528966, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4778261', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1473, 'n_words': 266}