PHP implementation of the text database data display, add, modify, delete, query five basic methods of operation

Source: Internet
Author: User
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.
  1. /**
  2. PHP implementation of the text database data display, add, modify, delete, query five basic methods of operation.
  3. This text database has a total of 9 fields:
  4. private $bankid;//Bank ID
  5. private $bankname;//Bank Name
  6. private $bankimg;//Bank pictures
  7. private $bankarea;//Coverage area
  8. private $bankcard;//Accept card type
  9. private $banklimit;//Payment limit
  10. private $bankpasswd;//Transaction password
  11. private $banknote;//Bank information notes
  12. private $bankmiss;//Bank other information content.
  13. @abstractTxtDB Store
  14. @access Public
  15. @authoryuchao1 @staff.sina.com.cn
  16. */
  17. Class Txtdb {
  18. Private $bankid; Bank ID
  19. Private $bankname; Bank name
  20. Private $bankimg; Bank pictures
  21. Private $bankarea; Coverage area
  22. Private $bankcard; Receiving card Type
  23. Private $banklimit; Payment limit
  24. Private $bankpasswd; Transaction password
  25. Private $banknote; Bank information notes
  26. Private $bankmiss; Bank other information
  27. Public Function __construct () {
  28. $bankid = ""; Bank ID
  29. $bankname = ""; Bank name
  30. $bankimg = ""; Bank pictures
  31. $bankarea = ""; Coverage area
  32. $bankcard = ""; Receiving card Type
  33. $banklimit = ""; Payment limit
  34. $BANKPASSWD = ""; Transaction Password Type
  35. $banknote = ""; Bank information notes
  36. $bankmiss = ""; Bank other information
  37. }
  38. /**
  39. * Add Data Program section.
  40. * $bankinfo Array List of bank information to insert
  41. * $bankinfo ["BankID"] $bankinfo ["Bankname"] $bankinfo ["bankimg"] $bankinfo ["Bankarea"]
  42. * $bankinfo ["Bankcard"] $bankinfo ["Banklimit"]
  43. * $bankinfo ["bankpasswd"] $bankinfo ["banknote"] $bankinfo ["Bankmiss"]
  44. * @return Boolean success True
  45. * Failed False
  46. */
  47. public static function Insert ($bankinfo) {
  48. $date = Date ("y-m-d h:i:s"); Get system time
  49. foreach ($bankinfo as $key = = $value) {
  50. $key = Trim ($value); Remove the space behind the bank's content.
  51. }
  52. try {
  53. $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.
  54. $STR = $bankinfo ["BankID"]. "|" . $bankinfo ["Bankname"]. "|" . $bankinfo ["Bankimg"]. "|" .
  55. $bankinfo ["Bankarea"]. "|" . $bankinfo ["Bankcard"]. "|" . $bankinfo ["Banklimit"]. "|" .
  56. $bankinfo ["BANKPASSWD"]. "|" . $bankinfo ["Banknote"]. "|" . $bankinfo ["Bankmiss"]. "|" . $date. "\ r \ n";
  57. Assign all bank data to Variable $str, "|" The purpose of this is to use the data interval symbol for future data segmentation.
  58. Fwrite ($fp, $STR); Writing data to a file
  59. Fclose ($FP); Close File
  60. The $banklist is the data that comes from the bank table only son.
  61. return true;
  62. } catch (Exception $e) {
  63. return false;
  64. }
  65. }
  66. public static function show () {
  67. Data Display program segment
  68. if (file_exists ("Banklist.txt")) {//detect if file exists
  69. $array = File ("Banklist.txt"); Reads the entire contents of the file into the array $array
  70. $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] ... )。
  71. }
  72. Var_dump ($arr);
  73. }
  74. /**
  75. * Data Modification Program Section
  76. * $bankinfo Array List of bank information to insert
  77. * $bankinfo ["BankID"] $bankinfo ["Bankname"] $bankinfo ["bankimg"] $bankinfo ["Bankarea"]
  78. * $bankinfo ["Bankcard"] $bankinfo ["Banklimit"]
  79. * $bankinfo ["bankpasswd"] $bankinfo ["banknote"] $bankinfo ["Bankmiss"]
  80. * @return Boolean success True
  81. * Failed False
  82. */
  83. public static function Alter ($BANKINFO) {
  84. $date = Date ("y-m-d h:i:s"); Get System Modification Time
  85. $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 ....
  86. $n = count ($list); Calculates the total number of banks in the $list content and assigns variables to the $n
  87. foreach ($bankinfo as $key = = $value) {
  88. $key = Trim ($value); Remove the space behind the bank's content.
  89. }
  90. if ($n > 0) {//If the number of banks is greater than 0
  91. $fp = fopen ("Banklist.txt", "w"); The file is opened in write-only mode banklist.txt
  92. for ($i = 0; $i < $n; $i + +) {//Enter loop
  93. if (Eregi ($bankinfo ["BankID"], $list [$i]) {//compares the bank BankID with the contents of the array unit $list
  94. $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
  95. $f [0] = $bankinfo ["BankID"];
  96. $f [1] = $bankinfo ["Bankname"];
  97. $f [2] = $bankinfo ["bankimg"];
  98. $f [3] = $bankinfo ["Bankarea"];
  99. $f [4] = $bankinfo ["Bankcard"];
  100. $f [5] = $bankinfo ["Banklimit"];
  101. $f [6] = $bankinfo ["bankpasswd"];
  102. $f [7] = $bankinfo ["banknote"];
  103. $f [8] = $bankinfo ["Bankmiss"];
  104. $f [9] = $date;
  105. $list [$i] = $f [0]. "|" . $f [1]. "|" . $f [2]. "|" . $f [3]. "|" . $f [4]. "|" . $f [5]. "|" . $f [6]. "|" . $f [7]. "|" . $f [8]. "|" . $f [9]. "\ r \ n";
  106. $list[the contents of an array cell to $i] with an array of $f with the delimiter "|" Replace.
  107. Break Jump out of the loop
  108. }
  109. }//Loop Terminator
  110. }
  111. for ($i = 0; $i <= $n; $i + +) {//Enter loop
  112. Fwrite ($fp, $list [$i]); Writes each cell of an array $list to a file banklist.txt
  113. }//Loop terminator
  114. Fclose ($FP); Close File
  115. }
  116. /**
  117. * Data Removal program segment
  118. * @param $bankid Bank ID number
  119. * @return Boolean true success
  120. * False failed
  121. *
  122. */
  123. public static function Delete ($bankid) {
  124. $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 ....
  125. $n = count ($list); Calculates the total number of banks in the $list content and assigns variables to the $n
  126. if ($n > 0) {//If the number of banks is greater than 0
  127. $fp = fopen ("Banklist.txt", "w"); The file is opened in write-only mode banklist.txt
  128. for ($i = 0; $i < $n; $i + +) {//Enter loop
  129. if (eregi ($bankid, $list [$i])) {//will be sent over the bank $bankid to match the strings in the array $list[$i]
  130. $list [$i] = ""; If the match succeeds, the $list[$i] is emptied (for deletion purposes)
  131. Break Jump out of the loop
  132. }
  133. }//Loop terminator
  134. for ($i = 0; $i <= $n; $i + +) {//Enter loop
  135. Fwrite ($fp, $list [$i]); Writes each cell of an array $list to a file banklist.txt
  136. }//Loop terminator
  137. Fclose ($FP); Close File
  138. }
  139. }
  140. /**
  141. * Data Query Program segment
  142. * @param $bankid Bank ID number
  143. * @return Boolean successfully returned ture
  144. * Failed to return false
  145. *
  146. */
  147. public static function Select ($bankid) {
  148. $id = 0;
  149. $list = File ("Banklist.txt"); Read the entire banklist.txt file to the array $list,
  150. Each element of an array is a bank ($list [0] is the first bank's data, $list [1] is the second bank's data ....
  151. $n = count ($list); Calculates the total number of banks in the $list content and assigns variables to the $n
  152. $bankid = Trim ($bankid);
  153. if (! $bankid) {//if $bankid is False
  154. echo "You didn't enter any keywords! "; For related display
  155. return false;
  156. } else {
  157. if ($n > 0) {//If the number of banks is greater than 0
  158. for ($i = 0; $i < $n; $i + +) {//Enter loop
  159. if (eregi ($bankid, $list [$i])) {//Enter the keyword to match the string in the array $list[$i]
  160. $row = Explode ("|", $list [$i]);
  161. $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.
  162. 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
  163. Echo $bankname;
  164. return $row;
  165. }
  166. }//Loop Terminator
  167. }
  168. }
  169. if ($id = = 0) {
  170. echo "Didn't find the bank with the keyword match!" ";
  171. return false;
  172. }//If $id=0 indicates that no match is found, display the relevant hints
  173. }
  174. Public Function __destruct () {
  175. }
  176. }
  177. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.