Connexion bdd
This commit is contained in:
39
Database/connexionBdd.php
Normal file
39
Database/connexionBdd.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Dba\Connection;
|
||||
|
||||
class connexionSQL {
|
||||
private static ?connexionSQL $instance = null;
|
||||
private $ip = '10.121.38.71';
|
||||
private $user = 'devEmile';
|
||||
private $pass = 'ileane69b';
|
||||
private $database = 'gsbbdcr';
|
||||
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->creerConnexion($this->ip, $this->database, $this->user, $this->pass);
|
||||
}
|
||||
|
||||
private function creerConnexion($serveur , $bdd , $nomUtilisateur , $motPasse) {
|
||||
// Définition de la source des données pour PDO
|
||||
$dsn = "mysql:host=$serveur;dbname=$bdd;charset=utf8mb4";
|
||||
// Création de l'objet $dbh, de type PDO, qui est la ressource d'accès à la base
|
||||
try {
|
||||
$dbh = new PDO($dsn, $nomUtilisateur, $motPasse);
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
die("Erreur de connexion : ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance(){
|
||||
if(self::$instance == null)
|
||||
{
|
||||
echo "Bonjour";
|
||||
self::$instance = new connexionSQL();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user