<?php

class database
{


    private static $_instance = null;

    private $_nom='';


    private $_prenom='';

    private $pdo;

    public function __toString() {

        return $this->getPrenom() .' '. strtoupper($this->getNom());
    }


    private function __construct($servername, $username,$password ,$dbname)
    {
        $this->pdo = new  PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }



    public static function getInstance($servername, $username,$password ,$dbname ) {

        if(is_null(self::$_instance)) {
            self::$_instance = new Database($servername, $username,$password ,$dbname);
        }

        return self::$_instance;
    }


    public function Query($sql)
    {
        return $this->pdo->query($sql);
    }

    public function Execute($sql)
    {
         $request = $this->pdo->prepare($sql);

        return $request->execute();
    }

    public function Prepare($sql)
    {
        $request = $this->pdo->prepare($sql);

        return $request;
    }



    public function getNom() {
        return $this->_nom;
    }

    public function getPdo() {
        return $this->pdo;
    }
    public function getPrenom()
    {
        return $this->_prenom;
    }
}

?>
