PHP implementation of the text database data display, add, modify, delete, query five basic methods of operation This text database has a total of 9 fields: Private $bankid; Bank ID Private $bankname; Bank name Private $bankimg; Bank pictures Private $bankarea; Coverage area Private $bankcard; Receiving card Type Private $banklimit; Payment limit Private $bankpasswd; Transaction password Private $banknote; Bank information notes Private $bankmiss; Other information content of the bank.
- /**
- PHP implementation of the text database data display, add, modify, delete, query five basic methods of operation.
- This text database has a total of 9 fields:
- private $bankid;//Bank ID
- private $bankname;//Bank Name
- private $bankimg;//Bank pictures
- private $bankarea;//Coverage area
- private $bankcard;//Accept card type
- private $banklimit;//Payment limit
- private $bankpasswd;//Transaction password
- private $banknote;//Bank information notes
- private $bankmiss;//Bank other information content.
- @abstractTxtDB Store
- @access Public
- @authoryuchao1 @staff.sina.com.cn
- */
- Class Txtdb {
- Private $bankid; Bank ID
- Private $bankname; Bank name
- Private $bankimg; Bank pictures
- Private $bankarea; Coverage area
- Private $bankcard; Receiving card Type
- Private $banklimit; Payment limit
- Private $bankpasswd; Transaction password
- Private $banknote; Bank information notes
- Private $bankmiss; Bank other information
- Public Function __construct () {
- $bankid = ""; Bank ID
- $bankname = ""; Bank name
- $bankimg = ""; Bank pictures
- $bankarea = ""; Coverage area
- $bankcard = ""; Receiving card Type
- $banklimit = ""; Payment limit
- $BANKPASSWD = ""; Transaction Password Type
- $banknote = ""; Bank information notes
- $bankmiss = ""; Bank other information
- }
- /**
- * Add Data Program section.
- * $bankinfo Array List of bank information to insert
- * $bankinfo ["BankID"] $bankinfo ["Bankname"] $bankinfo ["bankimg"] $bankinfo ["Bankarea"]
- * $bankinfo ["Bankcard"] $bankinfo ["Banklimit"]
- * $bankinfo ["bankpasswd"] $bankinfo ["banknote"] $bankinfo ["Bankmiss"]
- * @return Boolean success True
- * Failed False
- */
- public static function Insert ($bankinfo) {
- $date = Date ("y-m-d h:i:s"); Get system time
- foreach ($bankinfo as $key = = $value) {
- $key = Trim ($value); Remove the space behind the bank's content.
- }
- try {
- $fp = fopen ("Banklist.txt", "a"); Opens the Banklist.txt text file in write-only mode with the file pointer pointing to the end of the file.
- $STR = $bankinfo ["BankID"]. "|" . $bankinfo ["Bankname"]. "|" . $bankinfo ["Bankimg"]. "|" .
- $bankinfo ["Bankarea"]. "|" . $bankinfo ["Bankcard"]. "|" . $bankinfo ["Banklimit"]. "|" .
- $bankinfo ["BANKPASSWD"]. "|" . $bankinfo ["Banknote"]. "|" . $bankinfo ["Bankmiss"]. "|" . $date. "\ r \ n";
- Assign all bank data to Variable $str, "|" The purpose of this is to use the data interval symbol for future data segmentation.
- Fwrite ($fp, $STR); Writing data to a file
- Fclose ($FP); Close File
- The $banklist is the data that comes from the bank table only son.
- return true;
- } catch (Exception $e) {
- return false;
- }
- }
- public static function show () {
- Data Display program segment
- if (file_exists ("Banklist.txt")) {//detect if file exists
- $array = File ("Banklist.txt"); Reads the entire contents of the file into the array $array
- $arr = Array_reverse ($array); The data in the $array is inverted (that is, the first row of the last line, and so on) is read into every unit of the array $arr ($arr [0] ... )。
- }
- Var_dump ($arr);
- }
- /**
- * Data Modification Program Section
- * $bankinfo Array List of bank information to insert
- * $bankinfo ["BankID"] $bankinfo ["Bankname"] $bankinfo ["bankimg"] $bankinfo ["Bankarea"]
- * $bankinfo ["Bankcard"] $bankinfo ["Banklimit"]
- * $bankinfo ["bankpasswd"] $bankinfo ["banknote"] $bankinfo ["Bankmiss"]
- * @return Boolean success True
- * Failed False
- */
- public static function Alter ($BANKINFO) {
- $date = Date ("y-m-d h:i:s"); Get System Modification Time
- $list = File ("Banklist.txt"); Reads the entire banklist.txt file into an array of $list, each element of the array is a bank ($list [0] is the first bank of data, $list [1] is the first bank of data ....
- $n = count ($list); Calculates the total number of banks in the $list content and assigns variables to the $n
- foreach ($bankinfo as $key = = $value) {
- $key = Trim ($value); Remove the space behind the bank's content.
- }
- if ($n > 0) {//If the number of banks is greater than 0
- $fp = fopen ("Banklist.txt", "w"); The file is opened in write-only mode banklist.txt
- for ($i = 0; $i < $n; $i + +) {//Enter loop
- if (Eregi ($bankinfo ["BankID"], $list [$i]) {//compares the bank BankID with the contents of the array unit $list
- $f = Explode ("|", $list [$i]); If a match is found, the "|" As a delimiter, cut the bank information $list[$i] (Section $i Bank) and assign the data to the array $f
- $f [0] = $bankinfo ["BankID"];
- $f [1] = $bankinfo ["Bankname"];
- $f [2] = $bankinfo ["bankimg"];
- $f [3] = $bankinfo ["Bankarea"];
- $f [4] = $bankinfo ["Bankcard"];
- $f [5] = $bankinfo ["Banklimit"];
- $f [6] = $bankinfo ["bankpasswd"];
- $f [7] = $bankinfo ["banknote"];
- $f [8] = $bankinfo ["Bankmiss"];
- $f [9] = $date;
- $list [$i] = $f [0]. "|" . $f [1]. "|" . $f [2]. "|" . $f [3]. "|" . $f [4]. "|" . $f [5]. "|" . $f [6]. "|" . $f [7]. "|" . $f [8]. "|" . $f [9]. "\ r \ n";
- $list[the contents of an array cell to $i] with an array of $f with the delimiter "|" Replace.
- Break Jump out of the loop
- }
- }//Loop Terminator
- }
- for ($i = 0; $i <= $n; $i + +) {//Enter loop
- Fwrite ($fp, $list [$i]); Writes each cell of an array $list to a file banklist.txt
- }//Loop terminator
- Fclose ($FP); Close File
- }
- /**
- * Data Removal program segment
- * @param $bankid Bank ID number
- * @return Boolean true success
- * False failed
- *
- */
- public static function Delete ($bankid) {
- $list = File ("Banklist.txt"); Reads the entire banklist.txt file into an array of $list, each element of the array is a bank ($list [0] is the first bank of data, $list [1] is the first bank of data ....
- $n = count ($list); Calculates the total number of banks in the $list content and assigns variables to the $n
- if ($n > 0) {//If the number of banks is greater than 0
- $fp = fopen ("Banklist.txt", "w"); The file is opened in write-only mode banklist.txt
- for ($i = 0; $i < $n; $i + +) {//Enter loop
- if (eregi ($bankid, $list [$i])) {//will be sent over the bank $bankid to match the strings in the array $list[$i]
- $list [$i] = ""; If the match succeeds, the $list[$i] is emptied (for deletion purposes)
- Break Jump out of the loop
- }
- }//Loop terminator
- for ($i = 0; $i <= $n; $i + +) {//Enter loop
- Fwrite ($fp, $list [$i]); Writes each cell of an array $list to a file banklist.txt
- }//Loop terminator
- Fclose ($FP); Close File
- }
- }
- /**
- * Data Query Program segment
- * @param $bankid Bank ID number
- * @return Boolean successfully returned ture
- * Failed to return false
- *
- */
- public static function Select ($bankid) {
- $id = 0;
- $list = File ("Banklist.txt"); Read the entire banklist.txt file to the array $list,
- Each element of an array is a bank ($list [0] is the first bank's data, $list [1] is the second bank's data ....
- $n = count ($list); Calculates the total number of banks in the $list content and assigns variables to the $n
- $bankid = Trim ($bankid);
- if (! $bankid) {//if $bankid is False
- echo "You didn't enter any keywords! "; For related display
- return false;
- } else {
- if ($n > 0) {//If the number of banks is greater than 0
- for ($i = 0; $i < $n; $i + +) {//Enter loop
- if (eregi ($bankid, $list [$i])) {//Enter the keyword to match the string in the array $list[$i]
- $row = Explode ("|", $list [$i]);
- $id = 1; If a match is found, the "|" As a delimiter, cut the bank information $list[$i] (Section $i Bank) and assign the data to the array $row. and assign the variable $id to 1 so as to determine if a match is found.
- List ($bankid, $bankname, $bankimg, $bankarea, $bankcard, $banklimit, $bankpasswd, $banknote, $bankmiss) = $row; Assigns the cell data in the array $row sequentially to the variables in parentheses
- Echo $bankname;
- return $row;
- }
- }//Loop Terminator
- }
- }
- if ($id = = 0) {
- echo "Didn't find the bank with the keyword match!" ";
- return false;
- }//If $id=0 indicates that no match is found, display the relevant hints
- }
- Public Function __destruct () {
- }
- }
- ?>
Copy Code |