使用方法:结合txtdb.inc
初始用户和密码为:admin 123
CODE:
PHP
/*
TxtDb Manager
version: 0.1.0
Mail: psher@sina.com
This script is the manager for PHP txtDb.
#############################
Suppose Modify structrual
*/
include('txtdb.inc');
$root="txtdb";
$s_admins=array("admin","admin2","admin3");
$s_password="123";
####################
if(isset($_GET))@extract($_GET);
if(isset($_POST))@extract($_POST);
if(isset($_SESSION))@extract($_SESSION);
if(isset($_COOKIE))@extract($_COOKIE);
#################
if(isset($u_admin))$admin=$u_admin;
if(isset($u_password))$password=md5($u_password);
$s_password=md5($s_password);
$islogin=false;
if(($password==$s_password)and in_array($admin,$s_admins)){
setcookie('admin', $admin);
setcookie('password',$password);
$islogin=true;
if(isset($u_admin) and isset($u_password))echo"";
}
if($action=="quit"){
setcookie('admin');
setcookie('password');
$islogin=false;
echo "";
}
if(!$islogin and $action!="leftbar" and $action!="")$action="main";
#################
?>
Episome TxtDb Manager
##########################
if(!is_dir($root))
die('
Current TxtDb root does not exists!
');$db=new txtDb($root);
$version=$db->version;
############################
switch($action){
case "leftbar":
leftbar();
break;
case "main":
main();
break;
case "selecttable":
selecttable($table);
break;
case "viewdata":
viewdata($table,$start,$num,$sortby,$order,$keyword,$fields,$selectstring,$selectcolumn);
break;
case "newtable":
newtable($table,$tblfields);
break;
case "insertrecord":
insertrecord($table,$value,$id);
break;
case "delrecord":
delrecord($table,$id,$start,$num,$order,$sortby);
break;
case "editrecord":
editrecord($table,$id,$act,$value,$start,$num,$order,$sortby);
break;
case "droptable":
droptable($table);
break;
case "cleartable":
cleartable($table);
break;
default:
index();
}
/*
edit a row from table
*/
function editrecord($table,$id,$act,$value,$start,$num,$order,$sortby){
global $db;
$order=($order=="asc")?"desc":"asc";
$db->open($table,$id,1);
if($act=="save" and is_array($value)){
$db->change($value,$id);
echo "
The record of table [".$table."] has been modifyed !
";
echo " View data";
die();
}
echo"
Modify record of table [".$table."] !
|
";
}
/*
delete a row from table
*/
function delrecord($table,$id,$start,$num,$order,$sortby){
global $db;
$order=($order=="asc")?"desc":"asc";
$db->open($table,0,1);
$db->delete($id);
echo "
The record of table [".$table."] has been deleted !
";
echo " View data";
die();
}
/*
Insert a row to table
*/
function insertrecord($table,$value,$id){
global $db;
$db->open($table,0,1);
if(is_array($value)){
$db->append($value,$id);
echo "
The record has been inserted to table [".$table."]!
";
echo " View data";
echo " Insert record";
die();
}
echo"
Insert record to [".$table."]
";echo "
";
echo "
| ID |
";
}
/*
view data
*/
function viewdata($table,$start,$num,$sortby,$order,$keyword,$fields,$selectstring,$selectcolumn){
global $db;
if(trim($start)=='')$start=0;
if(trim($num)=='')$num=30;
$db->open($table,$start,$num);
if(trim($sortby)!='')
$db->sortby($sortby,$order);
$order=($order=="asc")?"desc":"asc";
$dbValues=$db->dbValues;
if(trim($keyword)!="")
$dbValues=$db->query($keyword,$fields);
if(trim($selectstring)!="")
$dbValues=$db->select($selectcolumn,$selectstring);
echo"
Data for Table [".$table."]
echo " | Edit Del | $id | ".htmlspecialchars($value)." |
Query :
|
Records : $db->lines
Insert record
Clear or Drop this table.
";
$db->times();
}
/*
select table
*/
function selecttable($table){
global $db;
$db->open($table,0,1);
echo "
Select Table [".$table."]
";
echo "Path : ".$db->tableName;
echo "Size : ".number_format(filesize($db->tableName))." (bytes)";
echo "Records : ".$db->lines;
echo "Fields :".$db->fields."
";
echo "";
foreach($db->fieldNames as $value){
echo "".$value;
}
echo "";
echo "";
echo "";
echo "";
echo " View data";
echo " Insert record";
echo " Clear or Drop this table.";
echo "Time of last modification : ".date ("F d Y H:i:s.", filemtime($db->tableName))."
";
clearstatcache();
$db->times();
}
/*
clear table
*/
function cleartable($table){
global $db;
$db->open($table,0,1);
$db->clear();
echo "
The table [".$table."] has been cleared !
";
}
/*
drop table
*/
function droptable($table){
global $db;
$db->open($table,0,1);
$db->drop();
echo "
The table [".$table."] has been droped !
";
echo "";
}
/*
create table
*/
function newtable($table,$tblfields){
global $db;
if(isset($table) and isset($tblfields)){
if(!ereg("^[-a-zA-Z0-9_.]",$table))
die(' Table name ['.$table.'] not allow!');
$tblfields=str_replace(" ","",$tblfields);
$fields=explode(" ",$tblfields);
foreach($fields as $key=>$value){
if(trim($value)=="")unset($fields[$key]);
}
if($db->create($table,$fields)){
echo "
The table [".$table."] has been created !
";
echo "";
die();
}
}
?>
Create New Table
TableName:
Fields: (field per line)
}
/*
show DB information
*/
function main(){
global $version,$islogin;
$httphost=$_ENV["HTTP_HOST"];
$server=$_SERVER["SERVER_SOFTWARE"];
$php=PHP_VERSION;
$os=PHP_OS;
echo"
Welcome to TxtDb Manager
TxtDb $version running on $httphost
PHP $php running on $os
Server_SoftWare : $server";
if(!$islogin){
echo "
";
}
echo "
";
}
/*
navigation bar
*/
function leftbar(){
global $db,$islogin;
?>
=$db->root?>
<?echo "
Actions
w Create Table |
w Exit Manager |
";
}
/*
show All tables
*/
function showtables($path){
global $db;
$dirhandle=opendir($path);
while($file=readdir($dirhandle)){
if ($file!="." && $file!=".."){
if (is_dir($path.'/'.$file)){
showtables($path.'/'.$file);
}else{
$path_info=pathinfo($file);
$exten=strtolower(".".$path_info["extension"]);
if($exten==strtolower($db->exten)){
if(strpos($path,'/')){
$file=str_replace($db->root.'/','',$path.'/'.$file);
$subdir=" ";
}
$file=str_replace($db->exten,'',$file);
echo "
$subdir w $file
";
}//
}
}
}
closedir($dirhandle);
}
/*
index of this manager
*/
function index(){
print'
';
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-959184/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752019/viewspace-959184/