Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ErnstJonesDatabaseServices {
- private static $instance;
- private $host = "localhost";
- private $user = "amacrae";
- private $pass = "Batton";
- private $base = "ernestjones";
- private function __construct() {
- }
- public static function getSingleton() {
- if(!isset(self::$instance)) {
- self::$instance = new ErnstJonesDatabaseServices();
- }
- return self::$instance;
- }
- public function getShortProductDetailsForCode($code) {
- $product = new stdClass();
- $con = new mysqli($this->host, $this->user, $this->pass, $this->base);
- $sql = "SELECT ProductName, Description1, MakeBrand, Price, Was FROM nn4m_ejproducts WHERE ModelNo = ?";
- $stmt = $con->prepare($sql);
- $stmt->bind_param('s', $code);
- $stmt->execute();
- $stmt->bind_result($row->name, $row->description, $row->make, $row->price, $row->was);
- if($stmt->fetch()) {
- $product = $row;
- }
- else {
- $product = null;
- }
- $stmt->close();
- $con->close();
- return $product;
- }
- public function getAllProductDetailsForXML($code) {
- $product = new stdClass();
- $con = new mysqli($this->host, $this->user, $this->pass, $this->base);
- $sql = "SELECT * FROM nn4m_ejproducts WHERE pid = ?";
- $stmt = $con->prepare($sql);
- $stmt->bind_param('s', $code);
- $stmt->execute();
- $stmt->bind_result($row->pid, $row->ProductName, $row->Description1, $row->Description2, $row->MakeBrand, $row->Price, $row->Was, $row->DeliveryCharge, $row->DeliveryTime, $row->ModelNo, $row->ProductCategory, $row->ProductSubcategory, $row->Availability);
- if($stmt->fetch()) {
- $product = $row;
- } else {
- $product = null;
- }
- $stmt->close();
- $con->close();
- return $product;
- }
- public function getDescriptionTwoForCode($code) {
- $descriptionTwoArray = array();
- $con = new mysqli($this->host, $this->user, $this->pass, $this->base);
- $sql = "SELECT Description2 FROM nn4m_ejproducts WHERE ModelNo = ?";
- $stmt = $con->prepare($sql);
- $stmt->bind_param('s', $code);
- $stmt->execute();
- $stmt->bind_result($descTwo);
- // echo "Code: ".$code."<br />";
- if($stmt->fetch()) {
- if($descTwo == "") {
- return $descriptionTwoArray;
- }
- //echo "Description2 is: ".$descTwo."<br />";
- // create new description 2 array
- // description 2 is in form key: value; etc...
- // first explode each one by ;
- $dItems = explode(';', $descTwo);
- foreach($dItems as $d) {
- $keyAndValue = explode(':', $d);
- $key = trim($keyAndValue[0]);
- $value = trim($keyAndValue[1]);
- $descriptionTwoArray[$key] = $value;
- }
- }
- else {
- $descriptionTwoArray = null;
- }
- return $descriptionTwoArray;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment