commit d1f0b54ff5e1d1ddb7d48c39a6aec9f588d7305b from: mischa date: Wed Aug 24 17:34:31 2022 UTC Exception handling for INSERT commit - 73c195712944b60fd577e279aee8d91176e77412 commit + d1f0b54ff5e1d1ddb7d48c39a6aec9f588d7305b blob - a9e681865a98b92a2c52b062a6c69410c4dbe5bc blob + 5e0c5f02efe11e9aaf2638dd1ed3e6e1c66e4431 --- index.php +++ index.php @@ -62,11 +62,13 @@ function generate_short($url, $dbh) { $sth->execute(); $loop++; } - $sth = $dbh->prepare("INSERT INTO " . DB_TABLE . " (id, url, ip, count) VALUES (?, ?, ?, '0')"); - $sth->bindParam(1, $hash, PDO::PARAM_STR, HASH_LENGTH); - $sth->bindParam(2, $url, PDO::PARAM_STR); - $sth->bindParam(3, $clientip, PDO::PARAM_STR, 255); - if (!$sth->execute()) { + try { + $sth = $dbh->prepare("INSERT INTO " . DB_TABLE . " (id, url, ip, count) VALUES (?, ?, ?, '0')"); + $sth->bindParam(1, $hash, PDO::PARAM_STR, HASH_LENGTH); + $sth->bindParam(2, $url, PDO::PARAM_STR); + $sth->bindParam(3, $clientip, PDO::PARAM_STR, 255); + $sth->execute(); + } catch (PDOException $e) { $hash = "ERROR
Failed to insert hash!"; } }