×Ô¼º¶¯ÊÖ×oÒ»¸oSQL½aÊÍÆ÷
ÔÚÒ»Ð(C)СÐ͵ÄÓ¦ÓÃÖУ¬ÍeȫûÓбØҪʹÓôoÐÍÊý¾Ý¿aÈi¼þ¡£×Ô¼º×oÒ»¸oSQL½aÊÍÆ÷¾ÍÄÜÓÃÊý¾Ý¿aµÄ*½Ê½À´¹ÜÀiÁË¡£
Õa¸o½aÊÍÆ÷£¬ÄܽaÊͳ£ÓõÄSQLÃuÁi¡£Äa¿ÉÒÔ×ÔÐÐÌi¼ÓÆaËu¹¦ÄÜ¡£
<?php
class DB_text {
var $conn;
var $classname = "db_text";
var $database;
function on_create() {
}
function connect($database_name) {
$this->database = $database_name;
if(! file_exists($database_name)) {
$this->conn = array();
$this->_close();
}
$fp = fopen($this->database,"r");
$this->conn = unserialize(fread($fp,filesize($this->database)));
fclose($fp);
}
function &query;($query) {
if(eregi("select ",$query)) return $this->_select($query);
if(eregi("insert ",$query)) return $this->_insert($query);
if(eregi("delete ",$query)) return $this->_delete($query);
if(eregi("update ",$query)) return $this->_update($query);
return array();
}
function fetch_row(&$result) {
if(list($key,$value) = each($result))
return $value;
return false;
}
function num_rows($result) {
return count($result);
}
/**
for($i=0;$i<count($ar);$i++) {
if(isset($t[0][$ar[$i]]))
$ar[$i] = "\$value[".$ar][$i]."]";
}
$expr = "\$expl=(".join(" ",$ar).");";
while(list($key,$value) = each($t)) {
eval($expr);
if($expl)
$keys[] = $key;
}
return $keys;
}
function _sort(&$ar,$key=0,$mode="desc") {
global $cmp_key;
$cmp_key = $key;
if($mode == "asc")
usort($ar,_cmp_asc);
else
usort($ar,_cmp_desc);
}
function _close() {
$fp = fopen($this->database,"w");
fwrite($fp,serialize($this->conn));
fclose($fp);
}
}
/* ÅÅÐo¼u
/
$cmp_key = "";
/* ÅÅÐoÓù¤×÷º¯Êý(½µÐo ÓÉusort()µ÷ÓÃ)
/
function _cmp_desc($a,$b) {
global $cmp_key;
if ($a[$cmp_key] == $b[$cmp_key]) return 0;
return ($a[$cmp_key] > $b[$cmp_key]) ? -1 : 1;
}
/* ÅÅÐoÓù¤×÷º¯Êý(ÉýÐo ÓÉusort()µ÷ÓÃ)
/
function _cmp_asc($a,$b) {
global $cmp_key;
if ($a[$cmp_key] == $b[$cmp_key]) return 0;
return ($a[$cmp_key] > $b[$cmp_key]) ? 1 : -1;
}
?>
²aÊÔÀý£º
$conn = new DB_text;
$conn->connect("text1.txt");$conn->query("insert into manage (id,title) values (10,'abcd')");
$conn->query("insert into manage (id,title) values (2,'43d')");
$conn->query("insert into manage (id,title) values (20,'tuu')");
$conn->query("update manage set id=101,test='a' where id=10");
//$conn->query("delete from manage where id='10'");
//$conn->query("delete from manage where id=10 or table='code'");//$rt = $conn->query("select from manage where id=101 or table='code' group by 1 order by 1 asc");
$rt = $conn->query("select from manage group by 1 order by id desc");print_r($rt);
?>