1er Class et erreur Undefined Variable
Bonjour,
J'ai fait la class suivante :
Code:
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
| class db {
private $pdo;
private $instance=null;
private $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" );
private $host = 'localhost';
private $db_name = '_erp';
private $user = 'root';
private $pass ='';
private $dns = '';
public function __construct() {
try {
$this->$dns = 'mysql:host='. $this->$host.';dbname='.$this->$db_name;
$this->instance = new PDO($this->$dns, $this->$user, $this->$pass, $this->$options);
$this->instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
$error='Impossible de se connecter à la base de donnée'.$e->getMessage() .'\n'.$dns.' '.$user.' '.$pass;
include'error.php.html';
exit();
}
}
public function getinstance() {
return $this->instance;
}
} |
Je lance ensuite :
J'obtiens une erreur : Notice: Undefined variable: host in ...
Je ne comprends pas pourquoi alors que j'ai bien déclarer ma variable avec $this->
Merci pour votre aide
Tornade