PHP implements the five basic operations of data display, adding, modifying, deleting and querying text databases
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;
//Card types accepted
private $banklimit;
//Payment limit
private $bankpasswd;
//Transaction password
private $banknote;
//Bank information remarks
private $bankmiss;
//Other information content of the bank.
- /**
- php implements the five basic operations of data display, adding, modifying, deleting and querying text databases.
- This text database has a total of 9 fields:
- private $bankid; //Bank ID
- private $bankname; //Bank name
- private $bankimg; //Bank picture
- private $bankarea; //Covered area
- private $bankcard; //Accepted card types
- private $banklimit; //Payment limit
- private $bankpasswd; //Transaction password
- private $banknote; //Bank information notes
- private $bankmiss; //Other bank information.
- @abstract TxtDB store
- @access public
- @author yuchao1@staff.sina.com.cn
-
- */
- class TxtDB {
-
- private $bankid; //Bank ID
- private $bankname; //Bank name
- private $bankimg; //Bank picture
- private $bankarea; //covered area
- private $bankcard; //accepted card types
- private $banklimit; //payment limit
- private $bankpasswd; //transaction password
- private $banknote; //bank information remarks
- private $ bankmiss; //Other bank information
-
- public function __construct() {
- $bankid = ""; //Bank ID
- $bankname = ""; //Bank name
- $bankimg = ""; //Bank picture
- $bankarea = ""; //Covered area
- $bankcard = ""; //Accepted card types
- $banklimit = ""; //Payment limit
- $bankpasswd = ""; //Transaction password type
- $banknote = " "; //Bank information notes
- $bankmiss = ""; //Other bank information
- }
- /**
- * Add data program segment.
- * $bankinfo array List of bank information to be inserted
- * $bankinfo["bankid"]$bankinfo["bankname"]$bankinfo["bankimg"]$bankinfo["bankarea"]
- * $bankinfo["bankcard"] $bankinfo["banklimit"]
- * $bankinfo["bankpasswd"]$bankinfo["banknote"]$bankinfo["bankmiss"]
- * @return boolean true on success
- * false on failure
- */
- public static function insert($bankinfo) {
- $date = date ( "Y-m-d H: i:s" ); //Get the system time
- foreach ( $bankinfo as $key => $value ) {
- $key = trim ( $value ); //Remove the spaces after the bank content.
- }
- try {
- $fp = fopen ( "banklist.txt", "a" ); //Open 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 . "rn";
- //Assign all bank data to the variable $str. The purpose of "|" is to use it as the data interval symbol when dividing data in the future.
- fwrite ($fp, $str); //Write data to the file
- fclose ($fp); //Close the file
- //The $banklist is the data passed from the bank form.
- return true;
- } catch (Exception $e) {
- return false;
- }
- }
-
- public static function show() {
- //Data display program segment
- if (file_exists ( "banklist.txt" )) { //Check whether the file exists
- $array = file ( "banklist.txt" ); // Read the entire contents of the file into the array $array
- $arr = array_reverse ( $array ); // Arrange the data in $array Flip the arrangement (i.e. the last row becomes the first row, and so on) and read each element of the array $arr ($arr[0]...).
- }
- var_dump ( $arr );
- }
-
- /**
- * Data modification program segment
- * $bankinfo array Bank information list to be inserted
- * $bankinfo["bankid"]$bankinfo["bankname"]$bankinfo["bankimg"]$bankinfo["bankarea"]
- * $ bankinfo["bankcard"]$bankinfo["banklimit"]
- * $bankinfo["bankpasswd"]$bankinfo["banknote"]$bankinfo["bankmiss"]
- * @return boolean true on success
- * false on failure
- */
- public static function alter($bankinfo) {
- $date = date ( "Y-m-d H:i:s" ); //Get System modification time
- $list = file ( "banklist.txt" ); //Read the entire banklist.txt file into the array $list, each element of the array is a bank ($list[0] is the data of the first bank , $list[1] is the first bank data....
- $n = count ( $list ); // Calculate the total number of banks in the $list content and assign it to the variable $n
- foreach ( $bankinfo as $key => $value ) {
- $key = trim ( $value ); //Remove the spaces after the bank content.
- }
- if ($n > 0) { //If the number of banks is greater than 0
- $fp = fopen ( "banklist.txt", "w" ); //Open the file banklist.txt in write-only mode
-
- for($i = 0; $i < $n; $i ++) { // Enter the loop
- if (eregi ( $bankinfo["bankid"], $list [$i] )) { // String matching and comparison of the passed bankid and the content in the array unit $list
- $f = explode ( "| ", $list [$i] ); //If a match is found, use "|" as the delimiter to cut the bank information $list[$i] (the $i-th bank), and assign these 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] . "rn";
- //Replace the contents of the array unit $list[$i] with the array $f plus the separator "|".
- break; //Get out of the loop
- }
- }//End of loop symbol
- }
- for($i = 0; $i <= $n; $i ++) { //Enter the loop
- fwrite ( $fp, $list [$i] ); //Convert each unit of the array $list into one line and write it to the file banklist.txt
- } //Loop end character
- fclose ( $fp ); // Close the file
- }
- /* *
- * Data deletion program segment
- * @param $bankid bank id number
- * @return boolean true success
- * false failure
- *
- */
- public static function delete($bankid) {
- $list = file ( "banklist.txt" ); //Read the entire banklist.txt file into the array $list, each element of the array is a bank ($list[0] is the data of the first bank, $list[1] is the data of the first bank...
- $n = count ( $list ); // Calculate the banks in the content of $list The total number and assigned to variable $n
- if ($n > 0) { //If the number of banks is greater than 0
- $fp = fopen ( "banklist.txt", "w" ); //Open the file in write-only mode banklist.txt
- for($i = 0; $i < $n; $i ++) { //Enter the loop
- if (eregi ( $bankid, $list [$i] )) { //Will be sent here Match and compare the bank's $bankid with the strings in the array $list[$i]
- $list [$i] = ""; //If the match is successful, $list[$i] will be cleared (to achieve the purpose of deletion) )
- break; //Jump out of the loop
- }
- } //Loop end character
- FOR($i = 0; $i <= $n; $i ++) { //Enter the loop
- fwrite ( $fp, $ list [$i] ); //Convert each unit of the array $list into one line and write it to the file banklist.txt
- } //Loop end character
- fclose ( $fp ); // Close the file
- }
- }
-
- /**
- * Data query program segment
- * @param $bankid bank ID number
- * @return boolean returns true on success
- * returns false on failure
- *
- */
- public static function select($bankid) {
- $id = 0;
- $list = file ( "banklist.txt" ); //Read the entire banklist.txt file into the array $list ,
- //Each element of the array is a bank ($list[0] is the data of the first bank, $list[1] is the data of the second bank...
- $n = count ( $list ); //Calculate the total number of banks in the $list content and assign it to the variable $n
- $bankid = trim ( $bankid );
- if (! $bankid) { //If $bankid is false
- echo "You did not enter anything Keyword! "; //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 the loop
- if (eregi ( $bankid, $list [$i] )) { // Match and compare the entered keywords with the strings in the array $list[$i]
- $row = explode ( "|", $list [$i] );
- $id = 1; //If a match is found, use "|" as the delimiter to cut the bank information $list[$i]($ith bank ), and assign these data to the array $row. And assign 1 to the variable $id to determine whether a match is found.
- list ($bankid,$bankname,$bankimg,$bankarea,$bankcard,$banklimit,$bankpasswd. ,$banknote,$bankmiss) = $row; //Assign the unit data in the array $row to the variables in the brackets in order
- //echo $bankname;
- return $row;
- }
- }//Loop end character
- }
- }
- if ($id == 0) {
- echo "No bank matching the keyword was found! ";
- return false;
- } //If $id=0, it means no match is found and relevant prompts are displayed
-
- }
-
- public function __destruct() {
-
- }
- }
- ?>
Copy code
|