Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <?php
  2.  
  3. class MyShoppingDB {
  4.  
  5. // PROPERTIES
  6. private $host = "localhost";
  7. private $username = "root";
  8. private $password = "";
  9. private $database = "shopping";
  10.  
  11. // METHODS
  12. /*
  13. * Description: Displays each element of the array.
  14. * Receives: Nothing
  15. * Returns: A one dimensional Array containing each username
  16. * of the user table.
  17. */
  18.  
  19. function getUsers() {
  20. $users = array();
  21. $strSQL = "SELECT * from users";
  22. $result = $this->selectQuery($strSQL);
  23. $nbrRows = mysql_numrows($result);
  24.  
  25. for ($i = 0; $i < $nbrRows; $i++) {
  26. $row = mysql_fetch_row($result);
  27. array_push($users, $row[0]);
  28. }
  29. return $users;
  30. }
  31.  
  32. /*
  33. * Description: Displays each element of the array.
  34. * Receives: A one dimensional Array.
  35. * Returns: Nothing
  36. */
  37.  
  38. function displayArray($arr) {
  39. foreach ($arr as $elem) {
  40. echo "$elem <br />";
  41. }
  42. }
  43.  
  44. /*
  45. * Description: Gets a resultset from the shopping database.
  46. * Receives: The SQL statement describing which data to retrieve.
  47. * Returns: A ResultSet
  48. */
  49.  
  50. function selectQuery($strSQL) {
  51. @mysql_connect($this->host, $this->username, $this->password) or die("Unable to connect");
  52. @mysql_select_db($this->database) or die("Could not find " . $this->database . "");
  53. $result = mysql_query($strSQL);
  54. mysql_close();
  55. return $result;
  56. }
  57.  
  58. }
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement