Bonsoir,
En voulant me connecter à ma base de donnée en PDO et POO, je rencontre une erreur.
Fatal error: Cannot redeclare class database in C:\xampp\htdocs\Forum\config\database.class.php on line 3
Fichier : database.class.php :
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
| <?php
class database {
protected $_host;
protected $_dbname;
protected $_username;
protected $_password;
public function __construct($_host, $_dbname, $_username, $_password) {
$this->_host = $_host;
$this->_dbname = $_dbname;
$this->_username = $_username;
$this->_password = $_password;
}
public function PDOConnexion() {
$bdd = new PDO('mysql:host='.$this->_host.'; dbname='.$this->_dbname, $this->_username, $this->_password);
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
}
?> |
Fichier index.php :
1 2 3 4 5
| <?php
require_once('config/database.class.php');
$connexion = new Database('localhost', 'Blablabla', 'root', '');
$connexion->PDOConnexion();
?> |
Un grand merci à ceux qui m'aideront !
Partager