Ec (2); this is from other places, and I will not write such boring things. & lt ;? PhpclassDB_text {var $ conn; var $ classname & quot; db_text & quot; var $ database; functionon_create () {} functionconnect ($ database_name) {$ this-& gt; data script ec (2); script
This is what we can see from other places. I won't write such boring things yet.
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 );
}
/**
* Auxiliary query Functions
*/
Function _ select ($ query ){
If (eregi ("(order by (.)", $ query, $ regs )){
$ Order = $ regs [2];
$ Query = eregi_replace ($ regs [1], "", $ query );
}
If (eregi ("(group by (.)", $ query, $ regs )){
$ Group = $ regs [2];
$ Query = eregi_replace ($ regs [1], "", $ query );
}
Eregi ("select. * from ([0-9a-z _]) * (where (.))? ", $ Query, $ regs );
If ($ regs [3]! = ""){
$ Keys = $ this-> _ where ($ regs [3], "$ this-> conn [$ regs [1]");
While (list ($ key, $ value) = each ($ keys )){
$ Rs [] = $ this-> conn [$ regs [1] [$ value];
}
} Else {
$ Rs = $ this-> conn [$ regs [1];
}
If ($ order ){
Sscanf ($ order, "% s", $ key, $ type );
If (empty ($ type) $ type = "asc ";
$ This-> _ sort ($ rs, $ key, $ type );
}
Return $ rs;