Guest User

Untitled

a guest
Jul 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. THIS CLASS CONTAINS DATABASE RELATED FUNCTIONS
  5.  
  6. FUNCTIONS USED IN THIS CLASS:
  7.  
  8. db_connect() Connects to the database
  9. db_select() Selects the database
  10. db_query() Queries the database
  11. db_error() Returns the database error
  12. db_close() Closes the connection to the database
  13.  
  14. count_rows() Returns the amount of rows in a result
  15.  
  16. */
  17.  
  18. class database
  19. {
  20. private $db_host = 'localhost';
  21. private $db_user = 'root';
  22. private $db_pass = '';
  23. private $db_name = 'escortz_db';
  24.  
  25. //
  26. // CONNECTS TO THE SERVER AND SELECTS THE DATABASE
  27. //
  28.  
  29. function database()
  30. {
  31. $this->database_connection = $this->db_connect($this->db_host, $this->db_user, $this->db_pass) or die($this->db_error());
  32. $this->db_select($this->db_name) or die($this->db_error());
  33.  
  34. // This will prevent some problems on MySQL5+ servers
  35. mysql_query("SET sql_mode='MYSQL40'", $this->database_connection);
  36. }
  37.  
  38. // END init()
  39.  
  40.  
  41.  
  42.  
  43.  
  44. //
  45. // CONNECT TO THE DATABASE
  46. //
  47.  
  48. function db_connect($db_host, $db_user, $db_pass)
  49. {
  50. return mysql_connect($this->db_host, $this->db_user, $this->db_pass, TRUE);
  51. }
  52.  
  53. // END db_connect()
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. //
  61. // THIS METHOD SELECTS A DATABASE
  62. //
  63.  
  64. function db_select($db_name)
  65. {
  66. return mysql_select_db($this->db_name, $this->database_connection);
  67. }
  68.  
  69. // END db_select()
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. //
  77. // THIS METHOD QUERIES A DATABASE
  78. //
  79.  
  80. function db_query($query)
  81. {
  82. $result = mysql_query($query, $this->database_connection);
  83. return $result;
  84. }
  85.  
  86. // END db_query()
  87.  
  88.  
  89.  
  90.  
  91. //
  92. // THIS METHOD RETURNS THE DATABASE ERROR
  93. //
  94.  
  95. function db_error()
  96. {
  97. return mysql_error($this->database_connection);
  98. }
  99.  
  100. // END db_error()
  101.  
  102.  
  103.  
  104.  
  105.  
  106. //
  107. // THIS METHOD CLOSES THE CONNECTION TO THE DATABASE SERVER
  108. //
  109.  
  110. function db_close()
  111. {
  112. return mysql_close($this->database_connection);
  113. }
  114.  
  115. // END db_close()
  116.  
  117.  
  118.  
  119.  
  120.  
  121. //
  122. // THIS METHOD RETURNS THE NUMBER OF ROWS IN A RESULT
  123. //
  124.  
  125. function count_rows($result)
  126. {
  127. if( !is_resource($result) ) return FALSE;
  128. return mysql_num_rows($result);
  129. }
  130.  
  131. // END database_row_count()
  132.  
  133.  
  134.  
  135.  
  136.  
  137. //
  138. // FETCHES A ROW AS A NUMERIC ARRAY
  139. //
  140.  
  141. function db_fetch_array($database_result)
  142. {
  143. if( !is_resource($database_result) ) return FALSE;
  144. return mysql_fetch_array($database_result);
  145. }
  146.  
  147. // END database_fetch_array()
  148.  
  149. }
  150. ?>
Add Comment
Please, Sign In to add comment