class KnivesModel {
private $db;
public function __construct($dsn, $user, $pass){
try{
$this->$db = new PDO($dsn, $user, $pass);
}catch(PDOException $e){
var_dump($e);
};
}; // __construct
}
This code breaks my app. I'm not even instantiating this class yet. All I do is include this class in my index.php and the "app" blows up with 500 error. What's the problem?
There should be no ;
at the end of the try catch
and the __construct
function.
Remove the ;
at the end of the constructor declaration and try/catch
block:
class KnivesModel {
private $db;
public function __construct($dsn, $user, $pass){
try{
$this->$db = new PDO($dsn, $user, $pass);
}catch(PDOException $e){
var_dump($e);
} // <<< Right here
} // <<< Right here
}