⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backup.inc.php

📁 学校网站源码http://您的网址/admin/admin_login.asp 默认登录用户:admin 默认登录密码:admin
💻 PHP
字号:
<?php


function get_table_def( $db, $table, $crlf )
{
	global $use_backquotes;
	$schema_create = "";
	if ( 32321 <= MYSQL_INT_VERSION )
	{
		if ( $use_backquotes )
		{
			mysql_query( "SET SQL_QUOTE_SHOW_CREATE = 1" );
		}
		else
		{
			mysql_query( "SET SQL_QUOTE_SHOW_CREATE = 0" );
		}
		$result = mysql_query( "SHOW CREATE TABLE ".backquote( $db ).".".backquote( $table ) );
		if ( $result != FALSE && 0 < mysql_num_rows( $result ) )
		{
			$tmpres = mysql_fetch_array( $result );
			$schema_create .= str_replace( "\n", $crlf, html_format( $tmpres[1] ) );
		}
		return $schema_create;
	}
	$schema_create .= "CREATE TABLE ".html_format( backquote( $table ), $use_backquotes )." (".$crlf;
	$local_query = "SHOW FIELDS FROM ".backquote( $db ).".".backquote( $table );
	if ( !( $result = mysql_query( $local_query ) ) )
	{
		mysql_die( "", $local_query );
	}
	while ( $row = mysql_fetch_array( $result ) )
	{
		$schema_create .= "   ".html_format( backquote( $row['Field'], $use_backquotes ) )." ".$row['Type'];
		if ( isset( $row['Default'] ) && $row['Default'] != "" )
		{
			$schema_create .= " DEFAULT '".html_format( sql_addslashes( $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 );
	$local_query = "SHOW KEYS FROM ".backquote( $db ).".".backquote( $table );
	if ( !( $result = mysql_query( $local_query ) ) )
	{
		mysql_die( "", $local_query );
	}
	while ( $row = mysql_fetch_array( $result ) )
	{
		$kname = $row['Key_name'];
		$comment = isset( $row['Comment'] ) ? $row['Comment'] : "";
		$sub_part = isset( $row['Sub_part'] ) ? $row['Sub_part'] : "";
		if ( $kname != "PRIMARY" && $row['Non_unique'] == 0 )
		{
			$kname = "UNIQUE|{$kname}";
		}
		if ( $comment == "FULLTEXT" )
		{
			$kname = "FULLTEXT|\$kname";
		}
		if ( !isset( $index[$kname] ) )
		{
			$index[$kname] = array( );
		}
		if ( 1 < $sub_part )
		{
			$index[$kname][] = html_format( backquote( $row['Column_name'], $use_backquotes ) )."(".$sub_part.")";
		}
		else
		{
			$index[$kname][] = html_format( backquote( $row['Column_name'], $use_backquotes ) );
		}
	}
	while ( list( $x, $columns ) = x )
	{
		$schema_create .= ",".$crlf;
		if ( $x == "PRIMARY" )
		{
			$schema_create .= "   PRIMARY KEY (";
		}
		else if ( substr( $x, 0, 6 ) == "UNIQUE" )
		{
			$schema_create .= "   UNIQUE ".substr( $x, 7 )." (";
		}
		else if ( substr( $x, 0, 8 ) == "FULLTEXT" )
		{
			$schema_create .= "   FULLTEXT ".substr( $x, 9 )." (";
		}
		else
		{
			$schema_create .= "   KEY ".$x." (";
		}
		$schema_create .= implode( $columns, ", " ).")";
	}
	$schema_create .= $crlf.")";
	return $schema_create;
}

function backquote( $a_name, $do_it = TRUE )
{
	if ( $do_it && 32306 <= MYSQL_INT_VERSION && !empty( $a_name ) && $a_name != "*" )
	{
		return "`".$a_name."`";
	}
	else
	{
		return $a_name;
	}
}

function html_format( $string )
{
	return $string;
}

function sql_addslashes( $a_string = "", $is_like = FALSE )
{
	if ( $is_like )
	{
		$a_string = str_replace( "\\", "\\\\\\\\", $a_string );
	}
	else
	{
		$a_string = str_replace( "\\", "\\\\", $a_string );
	}
	$a_string = str_replace( "'", "\\'", $a_string );
	return $a_string;
}

function get_table_content_fast( $db, $table, $add_query = "", $handler )
{
	global $use_backquotes;
	$local_query = "SELECT * FROM ".backquote( $db ).".".backquote( $table ).$add_query;
	if ( !( $result = mysql_query( $local_query ) ) )
	{
		mysql_die( "", $local_query );
	}
	if ( $result != FALSE )
	{
		$fields_cnt = mysql_num_fields( $result );
		$j = 0;
		for ( ;	$j < $fields_cnt;	$j++	)
		{
			$field_set[$j] = backquote( mysql_field_name( $result, $j ), $use_backquotes );
			$type = mysql_field_type( $result, $j );
			if ( $type == "tinyint" || $type == "smallint" || $type == "mediumint" || $type == "int" || $type == "bigint" || $type == "timestamp" )
			{
				$field_num[$j] = TRUE;
			}
			else
			{
				$field_num[$j] = FALSE;
			}
		}
		if ( isset( $GLOBALS['showcolumns'] ) )
		{
			$fields = implode( ", ", $field_set );
			$schema_insert = "INSERT INTO ".backquote( html_format( $table ), $use_backquotes )." (".html_format( $fields ).") VALUES (";
		}
		else
		{
			$schema_insert = "INSERT INTO ".backquote( html_format( $table ), $use_backquotes )." VALUES (";
		}
		$search = array( "\n", "\r", "\x1A" );
		$replace = array( "\\n", "\\r", "\\Z" );
		$isFirstRow = TRUE;
		@set_time_limit( 1200 );
		while ( $row = mysql_fetch_row( $result ) )
		{
			$j = 0;
			for ( ;	$j < $fields_cnt;	$j++	)
			{
				if ( !isset( $row[$j] ) )
				{
					$values[] = "NULL";
				}
				else if ( !empty( $row[$j] ) )
				{
					if ( $field_num[$j] )
					{
						$values[] = $row[$j];
					}
					else
					{
						$values[] = "'".str_replace( $search, $replace, sql_addslashes( $row[$j] ) )."'";
					}
				}
				else
				{
					$values[] = "''";
				}
			}
			if ( isset( $GLOBALS['extended_ins'] ) )
			{
				if ( $isFirstRow )
				{
					$insert_line = $schema_insert.implode( ",", $values ).")";
					$isFirstRow = FALSE;
				}
				else
				{
					$insert_line = "(".implode( ",", $values ).")";
				}
			}
			else
			{
				$insert_line = $schema_insert.implode( ",", $values ).")";
			}
			unset( $values );
			$insertlines .= $insert_line.";\n";
		}
		if ( isset( $GLOBALS['extended_ins'] ) )
		{
			$GLOBALS['GLOBALS']['tmp_buffer'] = ereg_replace( ",([^,]*)\$", ";\\1", $GLOBALS['tmp_buffer'] );
		}
	}
	return $insertlines;
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -