Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- final class DbHelper
- {
- private const host = "localhost";
- private const user = "root";
- private const pass = "marcin";
- private const database = "ai_shop";
- private static $conn;
- public static function Instance()
- {
- static $instance = null;
- if ($instance === null) {
- $instance = new DbHelper;
- }
- return $instance;
- }
- public function getProducts()
- {
- return self::$conn->query("select * from product utf8");
- }
- private function __construct()
- {
- self::$conn = new mysqli(self::host, self::user, self::pass, self::database);
- self::$conn->set_charset("utf8");
- if (self::$conn->connect_error) {
- die("Connection failed: " . self::$conn->connect_error);
- }
- }
- public function __destruct()
- {
- self::$conn->close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement