I'm trying to come up with a way to control what happends if some UPDATE/INSERTS into a BD fail.
private $db;
public function __construct() {
$dsn = 'mysql:dbname=BDNAME;host=localhost';
$this->db = new PDO($dsn, 'USEER', 'PASSWORD', array('charset' => 'utf8'));
}
public function createnewthingtodo($what,$where,$when,$how,$done){
$sql= "INSERT INTO TODOLIST (what,where,when,how,done) VALUES (:what, :where, :when, :how, :done)";
$st = $this->db->prepare ($sql);
$st->bindValue(':what',$what);
$st->bindValue(':where',$where);
$st->bindValue(':when',$when);
$st->bindValue(':how',$how);
$st->bindValue(':done',$done);
if($st->execute()){
return true;
}else{
return false;
}
}
This example is returning always false, if i delete the last "if" and put the execution part just below the last binvalue, it works just fine, but then i end up with no error handling, any ideas on how can i achieve this? Thanks for your time.