Hydratation Objet
Posté : 05 déc. 2014, 17:04
Bonjour.
Je souhaite créer une classe dans la quelle j'ai ma connexion à ma base de donnée et un fichier config pour hydrater les attributs de connexion.
Fichier Config
Classe
Mais cela ne marche pas...
Je souhaite créer une classe dans la quelle j'ai ma connexion à ma base de donnée et un fichier config pour hydrater les attributs de connexion.
Fichier Config
Code : Tout sélectionner
$bdd_host = 'xxx';
$bdd_port = '3306';
$bdd_login = 'xxx';
$bdd_name = 'xxx';
$bdd_pass = 'xxx';
Code : Tout sélectionner
class Blog extends PDO {
private $_bdd;
private $_bdd_host;
private $_bdd_port;
private $_bdd_login;
private $_bdd_name;
private $_bdd_pass;
private $_bdd_option;
public function __construct() {
require_once($_SERVER['DOCUMENT_ROOT'].'/admin/config.php');
$this->_bdd_host = $bdd_host;
$this->_bdd_port = $bdd_port;
$this->_bdd_login = $bdd_login;
$this->_bdd_name = $bdd_name;
$this->_bdd_pass = $bdd_pass;
try {
echo
$bdd = new PDO('mysql:host='.$this->_bdd_host.';port='.$this->_bdd_port.';dbname='.$this->_bdd_login, $this->_bdd_name, $this->_bdd_pass, $this->_bdd_option);
} catch(Exception $e) {
exit('Erreur : '. $e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM tab_ndd_name');
while ($donnees = $reponse->fetch())
}