mysql - Using PDO with INSERT (PHP) -
i've got
$sql = $db->prepare("insert `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 test if added or #1062 - duplicate entry '...' key 'alias'
i assume that's correct.
my question is: how test if added successfully?
you can check return value of $sql->execute()
, this:
if ($sql->execute()) { // query succeeded. } else { // query failed. $errorcode = $sql->errorcode(); }
for more information, see the documentation pdostatement (the class of prepared statements).
Comments
Post a Comment