Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DB
- {
- private static $_instance;
- private $pdo;
- private $dbUser = 'hellomoto';
- private $dbPassword = 'pass';
- private $dbName = 'training';
- private $dbHost = 'localhost';
- private function __construct() {
- try {
- $h = new PDO("mysql:host=$this->dbHost;dbname=$this->dbName", $this->dbUser, $this->dbPassword);
- } catch (PDOExeption $e) {
- die($e->getMessage());
- }
- $this->pdo = $h;
- }
- static protected function getInstance() {
- if (self::$_instance === null) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- private function __clone() {}
- private function __wakeup() {}
- public function Select($query) {
- $stmt = $this->pdo->query($query);
- $result = $stmt->fetch(PDO::FETCH_ASSOC);
- return $result;
- }
- }
- class ArticlesModel extends DB
- {
- private static $_instance;
- private $msql;
- static public function getInstance() {
- if (self::$_instance === null) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- public function __construct() {
- $this->msql = DB::getInstance();
- }
- public function articlesAll() {
- $query = "SELECT * FROM Articles";
- $result = $this->msql->Select($query);
- return $result;
- }
- }
- $art = ArticlesModel::getInstance()->articlesAll();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement