/** * gets all ram chips * * @param PDO $pdo PDO connection object * @return SplFixedArray all RamChips found * @throws PDOException when mySQL related errors occur **/ public static function getAllRamChips(\PDO $pdo) { // create query template $query = "SELECT productId, productName, manufacturerName, modelName, price FROM ramChip"; $statement = $pdo->prepare($query); $statement->execute(); // build an array of ram chips $ramChips = new SplFixedArray($statement->rowCount()); $statement->setFetchMode(PDO::FETCH_ASSOC); while (($row = $statement->fetch()) !== false) { try { $ramChip = new RamChip($row["productId"], $row["productName"], $row["manufacturerName"], $row["modelName"], $row["price"]); $ramChips[$ramChips->key()] = $ramChip; $ramChip->next(); } catch (Exception $exception) { // if the row couldn't be converted, rethrow it throw new PDOException($exception->getMessage(), 0, $exception); } } return $ramChips; }
<?php //put this on the top of the file require_once "/etc/apache2/capstone-mysql/encrypted-config.php"; require_once "ramchip.php"; $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/enajera2.ini"); //now you can use the PDO object normally $ramChip = new RamChip(null, 1, "this is from PHP"); $ramChip->insert($pdo); $ramChip->setProductId("now I added an id"); $ramChip->setProductName("now I added a name for the ram chip, many words"); $ramChip->setManufacturerName("now I added a manufacturer name for the ram chip, there is no need to worry"); $ramChip->setPrice("now I added a price for the ram chip, wow such price"); $ramChip->update($pdo); $ramChip->delete($pdo);