Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2. final class DbHelper
  3. {
  4. private const host = "localhost";
  5. private const user = "root";
  6. private const pass = "marcin";
  7. private const database = "ai_shop";
  8. private static $conn;
  9. public static function Instance()
  10. {
  11. static $instance = null;
  12. if ($instance === null) {
  13. $instance = new DbHelper;
  14. }
  15. return $instance;
  16. }
  17. public function getProducts()
  18. {
  19. return self::$conn->query("select * from product utf8");
  20. }
  21. private function __construct()
  22. {
  23. self::$conn = new mysqli(self::host, self::user, self::pass, self::database);
  24. self::$conn->set_charset("utf8");
  25. if (self::$conn->connect_error) {
  26. die("Connection failed: " . self::$conn->connect_error);
  27. }
  28. }
  29. public function __destruct()
  30. {
  31. self::$conn->close();
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement