I want to fetch some information from my mysql database in a class, so I'm passing in the PDO object into a __construct
function, and working from there. However, what's an elegant way of checking to see if the PDO object was correctly created, and that the connection is open when the Table
class is instantiated?
class Table{
public function __construct(PDO $db, $week){
try{
$query = $db -> query ("SELECT * FROM `table1` where `day` = 'monday'");
}
catch(PDOExeption $e){
echo 'error: '. $e->getMessage();
//die();
}
}
}
I don't think this code does what I want.