-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnexionBD.php
More file actions
42 lines (37 loc) · 1.34 KB
/
Copy pathconnexionBD.php
File metadata and controls
42 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// Déclaration d'une nouvelle classe
class connexionDB {
private $host = 'vzlab.xyz'; // nom de l'host
private $name = 'sc4zds_pouattara1'; // nom de la base de donnée
private $user = 'sc4zds_pouattara'; // utilisateur
private $pass = 'dO26Zl[(PK~J'; // mot de passe
private $connexion;
function __construct($host = null, $name = null, $user = null, $pass = null){
if($host != null){
$this->host = $host;
$this->name = $name;
$this->user = $user;
$this->pass = $pass;
}
try{
$this->connexion = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->name,
$this->user, $this->pass, array(PDO::MYSQL_ATTR_INIT_COMMAND =>'SET NAMES UTF8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
}catch (PDOException $e){
echo 'Erreur : Impossible de se connecter à la BDD !';
die();
}
}
public function query($sql, $data = array()){
$req = $this->connexion->prepare($sql);
$req->execute($data);
return $req;
}
public function insert($sql, $data = array()){
$req = $this->connexion->prepare($sql);
$req->execute($data);
}
}
// Faire une connexion à notre fonction
$DB = new connexionDB();
?>