Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. <?php
  2. class mysql
  3. {
  4. var $connection;
  5. var $data;
  6.  
  7. function mysql($host, $user, $pwd, $database, $charset)
  8. {
  9. $this->connection = NULL;
  10. $this->data = NULL;
  11.  
  12. $this->connection = mysqli_connect($host, $user, $pwd) or $this->error("mysql_connect error");
  13. mysqli_select_db($this->connection, $database) or $this->error("mysql_select_db error");
  14. mysqli_set_charset($this->connection, $charset);
  15. }
  16.  
  17. function restart($host, $user, $pwd, $database)
  18. {
  19. if ($this->data != NULL && $this->data != 1)
  20. mysqli_free_result($this->data);
  21.  
  22. if ($this->connection != NULL)
  23. mysqli_close($this->connection);
  24.  
  25. $this->connection = mysqli_connect($host, $user, $pwd) or $this->error("mysql_connect error");
  26. mysqli_select_db($this->connection, $database) or $this->error("mysql_select_db error");
  27. }
  28.  
  29. function fetch_row()
  30. {
  31. return mysqli_fetch_row($this->data);
  32. }
  33.  
  34. function fetch_array()
  35. {
  36. return mysqli_fetch_array($this->data);
  37. }
  38.  
  39. function result($row_num, $value_name)
  40. {
  41. return mysqli_result($this->data, $row_num, $value_name);
  42. }
  43.  
  44. function disconnect()
  45. {
  46. if ($this->connection != NULL)
  47. {
  48. mysqli_close($this->connection);
  49. $this->connection = NULL;
  50. }
  51. }
  52.  
  53. function num_rows()
  54. {
  55. return (mysqli_num_rows($this->data));
  56. }
  57.  
  58. function destroy()
  59. {
  60. if ($this->data != NULL && $this->data != 1)
  61. mysqli_free_result($this->data);
  62.  
  63. $this->disconnect();
  64. }
  65.  
  66. function query($query_string)
  67. {
  68. if ($this->data != NULL)
  69. {
  70. if ($this->data != 1)
  71. mysqli_free_result($this->data);
  72.  
  73. $this->data = NULL;
  74. }
  75.  
  76. $this->data = mysqli_query($this->connection, $query_string) or $this->error("mysql_query error");
  77.  
  78. if ($this->data)
  79. return TRUE;
  80. else
  81. return FALSE;
  82. }
  83.  
  84. function query_nodie($query_string)
  85. {
  86. if ($this->data != NULL && $this->data != 1)
  87. {
  88. if ($this->data != 1)
  89. mysqli_free_result($this->data);
  90.  
  91. $this->data = NULL;
  92. }
  93.  
  94. $this->data = mysqli_query($query_string, $this->connection);
  95.  
  96. if ($this->data)
  97. return TRUE;
  98. else
  99. return FALSE;
  100. }
  101.  
  102. function error($header)
  103. {
  104. die($header.": ".mysqli_error($this->connection));
  105. }
  106.  
  107. function lock($rule)
  108. {
  109. $this->query("LOCK TABLES $rule") or $this->error("mysql LOCK TABLES error");
  110. }
  111.  
  112. function unlock()
  113. {
  114. $this->query("UNLOCK TABLES") or $this->error("mysql UNLOCK TABLES error");
  115. }
  116. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement