-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.php
More file actions
32 lines (31 loc) · 1.19 KB
/
Copy pathconnection.php
File metadata and controls
32 lines (31 loc) · 1.19 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
<?php
class DB{
private $host = "localhost";
private $username = "root";
private $password = "";
private $database = "bid_ece";
private $db;
/*paramètres que prends la fontion DB qu'on a déclarer à la tête du header*/
public function __construct($host = null, $username = null, $password = null, $database =null){
if($host != null){
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
/**PDO pour se connecter à la base de données */
try{
$this->db = new PDO("mysql:host=".$this->host.";dbname=".$this->database, $this->username,
$this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING ));
}catch(PDOException $e){
die("Impossible de se connecter a la base");
}
}
/**méthode pour faire les requètes plus rapidement */
public function query($sql, $data = array()){
$req =$this->db->prepare($sql);
$req->execute($data);
return $req->fetchAll(PDO::FETCH_OBJ);
}
}