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

📄 db.php

📁 php网页设计
💻 PHP
📖 第 1 页 / 共 2 页
字号:
					if ($col[5]=="auto_increment") {$sql.=" auto_increment ";}					}								sql_query("create table $table ($sql)",false,-1,false);								# Add initial data				$data=str_replace("table_","data_",$file);				if (file_exists($path . "/" . $data))					{					$f=fopen($path . "/" . $data,"r");					while (($row = fgetcsv($f,5000)) !== false)						{						# Escape values						for ($n=0;$n<count($row);$n++)							{							$row[$n]=escape_check($row[$n]);							$row[$n]="'" . $row[$n] . "'";							if ($row[$n]=="''") {$row[$n]="null";}							}						sql_query("insert into $table values (" . join (",",$row) . ")",false,-1,false);						}					}				}			else				{				# Table already exists, so check all columns exist								# Load existing table definition				$existing=sql_query("describe $table",false,-1,false);												$file=$path . "/" . $file;				if (file_exists($file))					{					$f=fopen($file,"r");					while (($col = fgetcsv($f,5000)) !== false)						{						# Look for this column in the existing columns.						$found=false;						for ($n=0;$n<count($existing);$n++)							{							if ($existing[$n]["Field"]==$col[0]) {$found=true;}							}						if (!$found)							{							# Add this column.							$sql="alter table $table add column ";							$sql.=$col[0] . " " . $col[1];							if ($col[4]!="") {$sql.=" default " . $col[4];}							if ($col[3]=="PRI") {$sql.=" primary key";}							if ($col[5]=="auto_increment") {$sql.=" auto_increment ";}							sql_query($sql,false,-1,false);							}						}					}				}							# Check all indices exist			# Load existing indexes			$existing=sql_query("show index from $table",false,-1,false);								$file=str_replace("table_","index_",$file);			if (file_exists($path . "/" . $file))				{				$done=array(); # List of indices already processed.				$f=fopen($path . "/" . $file,"r");				while (($col = fgetcsv($f,5000)) !== false)					{					# Look for this index in the existing indices.					$found=false;					for ($n=0;$n<count($existing);$n++)						{						if ($existing[$n]["Key_name"]==$col[2]) {$found=true;}						}					if (!$found && !in_array($col[2],$done))						{						# Add this index.												# Fetch list of columns for this index						$cols=array();						$f2=fopen($path . "/" . $file,"r");						while (($col2 = fgetcsv($f2,5000)) !== false)							{							if ($col2[2]==$col[2]) {$cols[]=$col2[4];}							}												$sql="create index " . $col[2] . " on $table (" . join(",",$cols) . ")";						sql_query($sql,false,-1,false);						$done[]=$col[2];						}					}				}			}		}	}	function getval($val,$default)    {    # return a value from get/post or a default if neither set    if (array_key_exists($val,$_POST)) {return $_POST[$val];}    if (array_key_exists($val,$_GET)) {return $_GET[$val];}    if (array_key_exists($val,$_COOKIE)) {return $_COOKIE[$val];}    return $default;    }function getvalescaped($val,$default)    {    # return a value from get/post, escaped and SQL-safe    return escape_check(getval($val,$default));    }    function getuid()    {    # generate a unique ID    return strtr(mysql_escape_string(microtime() . " " . $_SERVER["REMOTE_ADDR"]),". ","--");    }function escape_check($text) #only escape a string if we need to, to prevent escaping an already escaped string    {    $text=mysql_escape_string($text);    # turn all \\' into \'    while (!(strpos($text,"\\\\")===false))        {        $text=str_replace("\\\\","\\",$text);        }    return $text;    }    function nicedate($date,$time=false,$wordy=false)	{	# format a MySQL ISO date in the UK style	if ((strlen($date)==0) || (substr($date,0,4)=="0000")) {return "-";}	if ($time) {return substr($date,8,2) . "/" . substr($date,5,2) . "/" . substr($date,2,2) . " "  . substr($date,11,5);} else {		if ($wordy) {global $lang;return substr($date,8,2) . " " . @$lang["months"][substr($date,5,2)-1] . " " . substr($date,2,2);	}	else {return substr($date,8,2) . "/" . substr($date,5,2) . "/" . substr($date,2,2);}	}		}	function redirect($url)	{	global $baseurl;	if (substr($url,0,1)=="/")		{		# redirect to an absolute URL		header ("Location: " . $url);		}	else		{		# redirect to a relative URL		header ("Location: " . $baseurl . "/" . $url);		}	exit();	}	function checkperm($perm)    {    # check that the user has the $perm permission    global $userpermissions;    if (!(isset($userpermissions))) {return false;}    if (in_array($perm,$userpermissions)) {return true;} else {return false;}    }    function pagename()	{	$urlparts=explode("/",$_SERVER["PHP_SELF"]);    $url=$urlparts[count($urlparts)-1];    return $url;    }    function text($name)	{	global $config_disable_nohelp_warning;	# Returns site text with name $name, or failing that returns dummy text.	global $site_text,$pagename,$language,$languages,$usergroup;	if (array_key_exists($language . "-" . $name,$site_text)) {return $site_text[$language . "-" .$name];} 		# Can't find the language key? Look for it in other languages.	reset($languages);foreach ($languages as $key=>$value)		{		if (array_key_exists($key . "-" . $name,$site_text)) {return $site_text[$key . "-" . $name];} 				}		return "";	}    function get_section_list($page)	{	return sql_array("select name value from site_text where page='$page' and name<>'introtext' order by name");	}function resolve_user_agent($agent)    {    if ($agent=="") {return "-";}    $agent=strtolower($agent);    $bmatches=array( # Note - order is important - first come first matched                    "firefox"=>"Firefox",                    "opera"=>"Opera",                    "safari"=>"Safari",                    "applewebkit"=>"Safari",                    "msie 3."=>"IE3",                    "msie 4."=>"IE4",                    "msie 5.5"=>"IE5.5",                    "msie 5."=>"IE5",                    "msie 6."=>"IE6",                    "msie 7."=>"IE7",                    "msie"=>"IE",                    "netscape"=>"Netscape",                    "mozilla"=>"Mozilla" #catch all for mozilla references not specified above                    );    $osmatches=array(                    "nt 6."=>"Vista",                    "nt 5.2"=>"WS2003",                    "nt 5.1"=>"XP",                    "nt 5.0"=>"2000",                    "nt 4.0"=>"NT4",                    "windows 98"=>"98",                    "linux"=>"Linux",                    "freebsd"=>"FreeBSD",                    "os x"=>"OS X",                    "mac_powerpc"=>"Mac",                    "sunos"=>"Sun",                    "psp"=>"Sony PSP"                    );    $b="???";$os="???";    foreach($bmatches as $key => $value)        {if (!strpos($agent,$key)===false) {$b=$value;break;}}    foreach($osmatches as $key => $value)        {if (!strpos($agent,$key)===false) {$os=$value;break;}}    return $os . " / " . $b;    }    function daily_stat($activity_type,$object_ref)	{	# Update the daily statistics after a loggable event.	# the daily_stat table contains a counter for each 'activity type' (i.e. download) for each object (i.e. resource)	# per day.	$date=getdate();$year=$date["year"];$month=$date["mon"];$day=$date["mday"];	
    # Set object ref to zero if not set.
    if ($object_ref=="") {$object_ref=0;}
    	# Find usergroup	global $usergroup;	if (!isset($usergroup)) {$usergroup=0;}		# First check to see if there's a row	$count=sql_value("select count(*) value from daily_stat where year='$year' and month='$month' and day='$day' and usergroup='$usergroup' and activity_type='$activity_type' and object_ref='$object_ref'",0);	if ($count==0)		{		# insert		sql_query("insert into daily_stat(year,month,day,usergroup,activity_type,object_ref,count) values ('$year','$month','$day','$usergroup','$activity_type','$object_ref','1')");		}	else		{		# update		sql_query("update daily_stat set count=count+1 where year='$year' and month='$month' and day='$day' and usergroup='$usergroup' and activity_type='$activity_type' and object_ref='$object_ref'");		}	}    	function check_access_key($resource,$key)	{	# Verify a supplied external access key	$c=sql_value("select count(*) value from external_access_keys where resource='$resource' and access_key='$key'",0);	if ($c==0) {return false;} else {return true;}	}  function check_access_key_collection($collection,$key)	{	$r=get_collection_resources($collection);	for ($n=0;$n<count($r);$n++)		{		# Verify a supplied external access key for all resources in a collection		$c=sql_value("select count(*) value from external_access_keys where resource='" . $r[$n] . "' and access_key='$key'",0);		if ($c==0) {return false;}		}		return true;	}function myrealpath($path) {         $path_parts = pathinfo($path);         return realpath($path_parts['dirname'])."/". $path_parts['basename']; }?>

⌨️ 快捷键说明

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