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 43 44 45 46 47 48 49 50
| <?php
class Connexion extends PDO {
private $bdd, $moteur, $hote, $login, $mdp, $base;
public function __construct() {
$fichier = ''. docRoot() .'config/sql.ini';
if(file_exists($fichier)) {
$config = parse_ini_file($fichier, true);
$this->moteur = $config['SQL']['moteur'];
$this->hote = $config['SQL']['hote'];
$this->login = $config['SQL']['login'];
$this->mdp = $config['SQL']['mdp'];
$this->base = $config['SQL']['base'];
try {
$this->bdd = new PDO($this->moteur .':host='. $this->hote .';dbname='. $this->base, $this->login, $this->mdp);
$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
exit('Erreur : '. $e->getMessage());
}
}
}
public function requete($requete) {
$this->bdd->quote($requete);
return $this->bdd->query($requete) or exit(print_r($this->bdd->errorInfo()));
}
public function fetch($resultat) {
return $resultat->fetchAll();
}
public function compteur($resultat) {
if(is_object($resultat)) {
echo 'ok';
} else {
echo 'pas ok';
}
var_dump($resultat);
return $resultat->rowCount();
}
public function close($resultat) {
return $resultat->closeCursor();
}
}
?> |
Partager