I’ve got
$sql = $db->prepare("INSERT INTO `aliases` (`alias`, `domain`, `added`, `enabled`) VALUES (:alias, :domain, :added, :enabled)");
$sql->bindValue(':alias', $alias);
$sql->bindValue(':domain', $domain);
$sql->bindValue(':added', time());
$sql->bindValue(':enabled', 1);
$sql->execute();
//how do I test if it was added or #1062 - Duplicate entry '...' for key 'alias'
I assume that’s correct.
My question is:
How do I test if it was added successfully?
You can check the return value of
$sql->execute(), like this:For more information, see the documentation for PDOStatement (the class of prepared statements).