Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database
- {
- private $connection;
- private static $_instance;
- private static $dbConfig = [
- 'host' => 'localhost',
- 'port' => 5433,
- 'database' => 'vova',
- 'db_user' => 'vova',
- 'db_pass' => 'vova'
- ];
- private function __construct() {
- $this->connection = new PDO(
- "pgsql:dbname=" . self::$dbConfig['database'] . ";"
- . "host=" . self::$dbConfig['host'] . ";"
- . "port=" . self::$dbConfig['port'] . ";"
- . "user=" . self::$dbConfig['db_user'] . ";"
- . "password=" . self::$dbConfig['db_pass']
- );
- }
- public static function getInstance()
- {
- if (!self::$_instance) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- public function getConnection() {
- return $this->connection;
- }
- private function __clone() {}
- }
- //////////////// Use //////////////////////////////////////////////
- $db = Database::getInstance(); ////////////////////////////////////
- $pgsql = $db->getConnection(); ////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- $query = "SELECT * FROM MyTable ORDER BY ID DESC LIMIT 10"; ///////
- $res = $pgsql->query($query)->fetchAll(); /////////////////////////
- ///////////////////////////////////////////////////////////////////
- print_r($res); ////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement