Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MyShoppingDB {
- // PROPERTIES
- private $host = "localhost";
- private $username = "root";
- private $password = "";
- private $database = "shopping";
- // METHODS
- /*
- * Description: Displays each element of the array.
- * Receives: Nothing
- * Returns: A one dimensional Array containing each username
- * of the user table.
- */
- function getUsers() {
- $users = array();
- $strSQL = "SELECT * from users";
- $result = $this->selectQuery($strSQL);
- $nbrRows = mysql_numrows($result);
- for ($i = 0; $i < $nbrRows; $i++) {
- $row = mysql_fetch_row($result);
- array_push($users, $row[0]);
- }
- return $users;
- }
- /*
- * Description: Displays each element of the array.
- * Receives: A one dimensional Array.
- * Returns: Nothing
- */
- function displayArray($arr) {
- foreach ($arr as $elem) {
- echo "$elem <br />";
- }
- }
- /*
- * Description: Gets a resultset from the shopping database.
- * Receives: The SQL statement describing which data to retrieve.
- * Returns: A ResultSet
- */
- function selectQuery($strSQL) {
- @mysql_connect($this->host, $this->username, $this->password) or die("Unable to connect");
- @mysql_select_db($this->database) or die("Could not find " . $this->database . "");
- $result = mysql_query($strSQL);
- mysql_close();
- return $result;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement