Guest User

Untitled

a guest
Dec 10th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <?php
  2.  
  3. class ErnstJonesDatabaseServices {
  4. private static $instance;
  5.  
  6. private $host = "localhost";
  7. private $user = "amacrae";
  8. private $pass = "Batton";
  9. private $base = "ernestjones";
  10.  
  11. private function __construct() {
  12. }
  13.  
  14. public static function getSingleton() {
  15. if(!isset(self::$instance)) {
  16. self::$instance = new ErnstJonesDatabaseServices();
  17. }
  18. return self::$instance;
  19. }
  20.  
  21. public function getShortProductDetailsForCode($code) {
  22. $product = new stdClass();
  23. $con = new mysqli($this->host, $this->user, $this->pass, $this->base);
  24.  
  25. $sql = "SELECT ProductName, Description1, MakeBrand, Price, Was FROM nn4m_ejproducts WHERE ModelNo = ?";
  26.  
  27. $stmt = $con->prepare($sql);
  28. $stmt->bind_param('s', $code);
  29. $stmt->execute();
  30. $stmt->bind_result($row->name, $row->description, $row->make, $row->price, $row->was);
  31. if($stmt->fetch()) {
  32. $product = $row;
  33. }
  34. else {
  35. $product = null;
  36. }
  37.  
  38. $stmt->close();
  39. $con->close();
  40.  
  41. return $product;
  42. }
  43.  
  44. public function getAllProductDetailsForXML($code) {
  45. $product = new stdClass();
  46. $con = new mysqli($this->host, $this->user, $this->pass, $this->base);
  47.  
  48. $sql = "SELECT * FROM nn4m_ejproducts WHERE pid = ?";
  49.  
  50. $stmt = $con->prepare($sql);
  51. $stmt->bind_param('s', $code);
  52. $stmt->execute();
  53. $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);
  54. if($stmt->fetch()) {
  55. $product = $row;
  56. } else {
  57. $product = null;
  58. }
  59.  
  60. $stmt->close();
  61. $con->close();
  62.  
  63. return $product;
  64. }
  65.  
  66. public function getDescriptionTwoForCode($code) {
  67. $descriptionTwoArray = array();
  68. $con = new mysqli($this->host, $this->user, $this->pass, $this->base);
  69.  
  70. $sql = "SELECT Description2 FROM nn4m_ejproducts WHERE ModelNo = ?";
  71.  
  72. $stmt = $con->prepare($sql);
  73. $stmt->bind_param('s', $code);
  74. $stmt->execute();
  75. $stmt->bind_result($descTwo);
  76. // echo "Code: ".$code."<br />";
  77. if($stmt->fetch()) {
  78. if($descTwo == "") {
  79. return $descriptionTwoArray;
  80. }
  81. //echo "Description2 is: ".$descTwo."<br />";
  82. // create new description 2 array
  83. // description 2 is in form key: value; etc...
  84. // first explode each one by ;
  85. $dItems = explode(';', $descTwo);
  86. foreach($dItems as $d) {
  87. $keyAndValue = explode(':', $d);
  88. $key = trim($keyAndValue[0]);
  89. $value = trim($keyAndValue[1]);
  90. $descriptionTwoArray[$key] = $value;
  91. }
  92. }
  93. else {
  94. $descriptionTwoArray = null;
  95. }
  96.  
  97. return $descriptionTwoArray;
  98. }
  99.  
  100. }
  101.  
  102. ?>
Add Comment
Please, Sign In to add comment