PHP Data processing public class

Source: Internet
Author: User
Tags rtrim
  1. /*==================================================================*/
  2. /* File name: BaseLogic.class.php */
  3. /* Summary: Data processing public class. */
  4. Class Baselogic extends MyDB {
  5. protected $tabName; Name of the table
  6. protected $fieldList; Field Collection
  7. protected $messList;
  8. //==========================================
  9. Function: Add ($postList)
  10. Features: Adding
  11. Parameters: List of variables submitted $postList
  12. Return: The self-increment ID just inserted
  13. //==========================================
  14. function Add ($postList) {
  15. $fieldList = ";
  16. $value = ";
  17. foreach ($postList as $k = = $v) {
  18. if (In_array ($k, $this->fieldlist)) {
  19. $fieldList. = $k. ",";
  20. if (!GET_MAGIC_QUOTES_GPC ())
  21. $value. = "'". Addslashes ($v). "',";
  22. Else
  23. $value. = "'". $v. "',";
  24. }
  25. }
  26. $fieldList =rtrim ($fieldList, ",");
  27. $value =rtrim ($value, ",");
  28. $sql = "INSERT into {$this->tabname} (". $fieldList. ") VALUES (". $value.") ";
  29. Echo $sql;
  30. $result = $this->mysqli->query ($sql);
  31. if ($result && $this->mysqli->affected_rows >0)
  32. return $this->mysqli->insert_id;
  33. Else
  34. return false;
  35. }
  36. //==========================================
  37. Function: MoD ($postList)
  38. Function: Modify table Data
  39. Parameters: List of variables submitted $postList
  40. //==========================================
  41. function mod ($postList) {
  42. $id = $postList ["id"];
  43. unset ($postList ["id"]);
  44. $value = ";
  45. foreach ($postList as $k = = $v) {
  46. if (In_array ($k, $this->fieldlist)) {
  47. if (!GET_MAGIC_QUOTES_GPC ())
  48. $value. = $k. "=". Addslashes ($v). "',";
  49. Else
  50. $value. = $k. "=". $v. "',";
  51. }
  52. }
  53. $value =rtrim ($value, ",");
  54. $sql = "UPDATE {$this->tabname} SET {$value} WHERE id={$id}";
  55. return $this->mysqli->query ($sql);
  56. }
  57. //==========================================
  58. function: Del ($id)
  59. Function: Delete
  60. Parameters: $id number or ID list array
  61. Returns: 0 number of records failed successfully for deletion
  62. //==========================================
  63. Function del ($id) {
  64. if (Is_array ($id))
  65. $tmp = "In (". Join (",", $id). ")";
  66. Else
  67. $tmp = "= $id";
  68. $sql = "DELETE from {$this->tabname} WHERE ID". $tmp;
  69. return $this->mysqli->query ($sql);
  70. }
  71. function Get ($id) {
  72. $sql = "Select * from {$this->tabname} WHERE ID ={$id}";
  73. $result = $this->mysqli->query ($sql);
  74. if ($result && $result->num_rows ==1) {
  75. return $result->fetch_assoc ();
  76. }else{
  77. return false;
  78. }
  79. }
  80. function Getmesslist () {
  81. $message = "";
  82. if (!empty ($this->messlist)) {
  83. foreach ($this->messlist as $value) {
  84. $message. = $value. "
    ";
  85. }
  86. }
  87. return $message;
  88. }
  89. }
  90. ?>
Copy Code
Php
  • Related Article

    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.