PHP text data sheet

zhaozj2021-02-16  41

Just learning PHP, because the website space does not support the database, this class is written, just practice exercises.

This Class Is for Small Information Database So Like Classmater Database, They Are Less Than 300 Recorders.if Your Want Store and Opreat More Than 300 Recorder, It's Recommandly To Use SQL Server.

Your may acess the Instance of this Class with bellow function, there recommandly Do NOT useinner var and function, because that's unsafe.create () drop () open () close () eof () bof () prev () next () first () end ()

Fieldscount () getValue () setValue ()

Display () location ()

Recno () Recount ()

Del () append ()

* / define ("tblpath", ".//"); define ("eXten", "pHP"); define ("filehead", "

Function Create ($ TBLNAME, $ FIELDS, $ SPRT1 = "<--- txttbl ---> / n", $ sprt2 = "<- txttbl --->") {= ($ TBLNAME)) {echo "The textDateBase file name not appoint."; return false;} $ fullName = tblPath $ tblName.exten;. if (file_exists ($ fullName)) {echo "The textDateBase file is already exist."; return false;} IF (Empty ($ FIELDS)) {echo "The Fields List Array Is Invalid."; Return False;} $ Cont = Implode ($ SPRT2, $ FIELDS); $ Cont = Filehead. "/ n". $ up; $ FP = FOPEN ($ FULLNAME, "W"); FWRITE ($ FP, $ Cont); fclose ($ fp); return true;}

Function Drop ($ TBLNAME, $ SPRT1 = "<- TXTTBL ---> / N", $ SPRT2 = "<- TXTTBL --->") {IF (EMPTY ($ TBLNAME)) {echo " The TextdateBase File Name Not Proveid. ";} If (! EMPTY ($ this-> innername) {echo" current file not close, please close it and try again. "; Return false;} $ fullname = tblpath . $ TBLNAME.EXTEN; if (! File_exists ($ 50)) {echo "The textdatebase file not exist."; Return False;} $ fp = fopen ($ fullname, "r"); if (! Feof ($ fp) )) {$ Readfromfile = fgets ($ fp);} if ($ readfromfile! = Filehead. "/ N") {fclose ($ fp); echo "NOT I Valid TextDatabase File (The Head Is Invalid.)". "/ n"; return false;} $ readfromfile = ""; if (! Feof ($ fp)) $ readfromfile. = fgets ($ fp); $ readfromfile = Trim ($ readfromfile); if (EMPTY ($ readfromfile) {echo "not a valid textdatabase file. (can't Find Fields Define); Return False;} $ cont = filehead." / n ". $ readfromfile; $ fp = fopen ($ fopen Fullname, "W"); FWRITE ($ fp, $ last); fclose ($ fp); return true;} function open ($ TBLNAME, $ SPRT1 = "<--- txttbl ---> / N ", $ SPRT2 =" <--- txttbl ---> ") {IF (Empty ($ TBLNAME)) {Echo" The TextdateBase File Name Not ProveId. "; Return False;} if (! EMPTY) This-> InnerName)) {Echo "Current File Not Closed, Please Close It and Try Again."; Return False;} $ THIS-> Fullname = TBLPATH. $ TBLNAME.EXTEN; if (! file_exists ($ this-> fullname )) {Echo "The textdatebase file not exist."; Return False;} $ fp = fopen ($ this-> fullname, "r"); if (! Feof ($ fp)) {$ readfromfile = fgets ($ fp) }}} ($ Readfromfile! = Filehead. "

/ n ") {fclose ($ fp); echo" not a valid textdatable file. "" / n "; returnaf false;} $ readfromfile ="; while (! feof) )) $ readfromfile. = fgets ($ fp); $ readfromfile = trim ($ readfromfile); if ($ readfromfile) {echo "not a valid textDatabase file. (can't Find Fields) ($ this-> innerrecorders = expende; $ this-> innercount = count ($ this-> innerRecorders) - 1; $ this-> innerfields = evLode ($) SPRT2, $ this-> InnerRecorders [0]); $ this-> innerfieldscount = count ($ this-> innerfields); $ this-> innername = $ tblname; $ this-> sprt1 = $ sprt1; $ this-> sprt2 = $ SPRT2;

IF ($ this-> innercount == 0) {$ this-> curline = 0; $ this-> innereof = true;} else {$ this-> curline = 1; // if ($ this-> innercount == 1) $ this-> inNereof = true; if (! $ This-> initrec ()) Return False;}

Return True;}

Function close () {if ($ this-> innername) Return True; // Save Modify $ Ismodify = false; if ($ this-> ismodify) {$ this-> savemodify (); $ ismodify = true; } IF ($ this-> stringdel) {$ ismodify = true; $ DELNO = EXPLODE (",", $ this-> stringdel); Foreach ($ DELNO AS $ No) {$ no = (Integer) NO; unset ($ no);}}} f ($ ismodify || $ this-> filemodify) {$ recorders = Implode ($ this-> sprt1, $ this-> innerRecorders); $ recorders = FileHead. "/ n". $ recorders; $ fp = fopen ($ this-> fullname, "w"); fwrite ($ fp, $ recorders); fclose ($ fp);} $ this-> innername = " "; Unset ($ this-> innerRecorders); unset ($ this-> curay);

Function next () {if ($ this-> innereof) && (! Empty ($ this-> innerName)) {ified ($ this-> curline == $ this-> innercount) {$ this-> inNereof = True; Return True; $ this-> savemodify (); $ this-> curline ; if ($ this-> innerbof) $ this-> innerbof = false; $ this-> initRec ();} return false;} Function prev () {IF ($ this-> innerbof) && (! Empty ($ this-> innerName)))))) {$ this-> savemodify (); $ this-> curline--; if ($ this- > curline == 1) $ this-> innerbof = true; if ($ this-> innereof) $ this-> innereof = false; $ this-> init ();}}

Function first () {ix ($ this-> innerbof || Empty ($ this-> innername) Return False; $ this-> savemodify (); $ this-> curline = 1; $ this-> innerbof = true; $ this-> innereof = false; $ this-> initrec ();} function end () {=} function end () {=} ($ this-> innerName) Return False; $ this-> savemodify () $ This-> curline = $ this-> innercount; $ this-> innereof = true; $ this-> innerbof = false; $ this-> init ();} function EOF () {i (Empty ($ this- > InnerName)) {Return false;} else return $ this-> innereof;

Function Bof () {IF (Empty ($ this-> innerName) {Return True;} else return}} else return;}

Function recno () {RETURN $ this-> curline;}

Function Recount () {RETURN $ THIS-> InnerCount;}

Function Fieldscount () {if ($ this-> innerName) {Return False;} else return $ this-> inner_f_count;}

Function getValue ($ FIELD) {IF ($ this-> curline == 0 || EMPTY ($ this-> innername) {echo "can't read current record, maybe not in use or no record."; Return False } $ FIELD = $ this-> chkfield ($ field); if ($ field == - 1) {Return false;} Return $ this-> curay [$ field];} Function SetValue ($ FIELD, $ VALUE) {IF ($ this-> curline == 0 || EMPTY ($ this-> innername)) {echo "can't read current record, maybe not in use or no record."; Return false;} $ field = $ This-> Chkfield ($ FIELD); if ($ FIELD == - 1) {Return False; $ this-> curay [$ field] = $ value; $ this-> modify = true;} Function Display ($ shownon = 0, $ SPRT1 = "", $ SPRT2 = "", $ SPRT3 = "", $ SPRT4 = "") {Echo $ SPRT3; Foreach ($ THIS -> CuraRray as $ v) {IF ($ shownon == 1 && Empty ($ V)) $ V = "novalue"; Echo $ sprt1. $ V. $ sprt2;} echo $ sprt4;}

Function Location ($ FIELD, $ KeyValue) {$ FIELD = $ this-> Chkfield ($ FIELD); if ($ FIELD == - 1) Return False; for ($ I = $ this-> curline; $ i <= $ this-> innercount; $ i ) {IF ($ this-> curay [$ field] == $ keyvalue) {return true;} $} Return False;} Function Del ($ Recno = -1) {IF ($ this-> curline == 0) Return False; $ VARTYPE = GetType ($ Recno); if ($ VARTYPE! = "Integer") {echo "DEL Error: Check Ur Para Type."; Return false;} f ($ recno == - 1) {$ recno = $ this-> curline;} elseif ($ recno> $ this-> innercount || $ recno <1) {echo "DEL ERROR: OUT over the Rang. ";}} = f ($ recno)) {IF (isset ($ this-> stringdel) {$ this-> stringdel. = (','. $ recno; } else $ this-> stringdel = (string) $ recno;} else return false;} Function Append ($ FIELDS = ") {$ this-> savemodify (); for ($ i = 1; $ i <= $ this-> Innerfieldscount; $ i ) $ newrec [] = ""; if (! EMPTY ($ FIELDS)) {Foreach ($ FIELDS AS $ K => $ V) {$ K = $ THIS-> Chkfield ($ K) ); If ($ k == - 1) {return false;} $ newrec [$ k] = $ v;}} $ this-> innerco Unt ; $ this-> curline = $ this-> innercount; $ this-> innerbof = false; $ this-> innereof = true; unset ($ this-> curay); $ this-> curay = & $ newrec; $ This-> ismodify = true;} // Save Function SaveModify () {i ($ this-> ismodify) {$ this-> innerRecorders [$ this-> curline] = IMPLode ($ this-> sprt2, $ this- > curay); $ this-> ismodify = false; $ this-> filemodify = true;}}

// When the pointer changes, the current record array function initrec () {$ this-> curay = expende ($ this-> sprt2, $ this-> innerrecorders [$ this-> curline]); if (count ($ This-> curay)! = $ this-> innerfieldscount) {echo "The Current Recorder Fields Count UNEQUAL to TABLE'S. / N File Will Close."; $ this-> close (); return false;} return true;} / Output Current Record Information, Design to Debug Function DdisPlay () {IF ($ this-> InnerCount == 0) Return False; Foreach ($ this-> Innerfields as $ V) Echo $ V. "----" Echo "
"; Foreach ($ this-> Curay AS $ V) Echo $ V. "---";

// Check the record that has been removed in Function Chkdel ($ Key) {IF (Empty ($ Key) && $ Key! = 0) {echo "The key not appoint."; Return false;} if (! Isset ($ this -> stringdel)) {Return False;} IF (EREG ("(^ |,)". $ key. "(, | $)", $ this-> stringdel) {Return true;} Return False;

// Check if the submitted field name is legal. Function Chkfield ($ FIELD) {IF (Empty ($ Field! = 0)) {echo "The Field Not Appoint."; Return -1;} $ VARTYPE = GetType ($ field); Switch ($ VARTYPE) {CASE "Integer": IF ($ FIELD> = $ this-> innerfieldscount) {echo "The Field Is Large Than Fieldscount"; return -1;} elseif ($ field) <0) {Echo "The Field IS Less Than 0"; return -1;} Return $ field; Case "string": foreach ($ this-> innerfields as $ k => $ V) IF ($ FIELD == $ v) Return $ K; Echo "The Field Name Not Found."; Return -1; Default: Echo "The Field Is Invalid."; Return -1;}}

}?>

转载请注明原文地址:https://www.9cbs.com/read-24949.html

New Post(0)