$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO cinema (name, genre, year, oscar, watched) VALUES(?,?,?,?,?)";
$q = $pdo->prepare($sql);
$q->execute(array($name, $genre, $year, $oscar, $seen));
Database::disconnect();
答案 0 :(得分:0)
在执行INSERT之前再做一次查询:
SELECT COUNT(*) as c FROM cinema WHERE name = ? and year = ?
执行常规的准备/绑定/获取内容和if ($row['c'] > 0)
然后输出错误消息 - 否则您将继续使用INSERT
。