Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Thylane ECHARDOUR
Yearbook des diplômés
Commits
027372b4
Commit
027372b4
authored
Oct 29, 2021
by
Baptiste DOUXAMI
Browse files
Upload New File
parent
3cfb7ff9
Changes
1
Hide whitespace changes
Inline
Side-by-side
modele/BDconnexion.php
0 → 100644
View file @
027372b4
<?php
require_once
"SalonException.php"
;
class
BDConnexion
{
private
$connexion
;
private
static
$instancePDO
;
// constructeur qui permet de créer la connexion au sgbd
private
function
__construct
(){
$chaine
=
"mysql:host="
.
HOST
.
";dbname="
.
BD
;
try
{
$this
->
connexion
=
new
PDO
(
$chaine
,
LOGIN
,
PASSWORD
);
$this
->
connexion
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
}
catch
(
PDOException
$e
){
throw
new
ConnexionException
(
"problème de connexion"
);
}
}
/** méthode qui implémente le patron singleton qui ne permet d'utiliser qu'une instance d'objet de type PDO (unze seule connexion au sgbd)
@return la seule instance d'objet PDO
*/
public
static
function
getInstance
():
BDConnexion
{
if
(
is_null
(
self
::
$instancePDO
)){
self
::
$instancePDO
=
new
BDConnexion
();
}
return
self
::
$instancePDO
;
}
/** méthode qui permet de retourner une connexion
@return un objet de type PDO
*/
public
function
getConnexion
():
PDO
{
return
$this
->
connexion
;
}
/** méthode qui permet de gérer la déconnexion au sgbd
*/
public
function
deconnexion
():
PDO
{
$this
->
connexion
=
null
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment