Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 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: Gets a resultset from the shopping database.
  34.      * Receives: The SQL statement describing which data to retrieve.
  35.      * Returns: A ResultSet
  36.      */
  37.  
  38.     function selectQuery($strSQL) {
  39.         @mysql_connect($this->host, $this->username, $this->password) or die("Unable to connect ya maniac.");
  40.         @mysql_select_db($this->database) or die("Could not find " . $this->database . " ya maniac");
  41.         $result = mysql_query($strSQL);
  42.         mysql_close();
  43.         return $result;
  44.     }
  45.  
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement