Exception handling for INSERT

This commit is contained in:
mischa 2022-08-24 17:34:31 +00:00
parent 73c1957129
commit d1f0b54ff5
1 changed files with 7 additions and 5 deletions

View File

@ -62,11 +62,13 @@ function generate_short($url, $dbh) {
$sth->execute(); $sth->execute();
$loop++; $loop++;
} }
$sth = $dbh->prepare("INSERT INTO " . DB_TABLE . " (id, url, ip, count) VALUES (?, ?, ?, '0')"); try {
$sth->bindParam(1, $hash, PDO::PARAM_STR, HASH_LENGTH); $sth = $dbh->prepare("INSERT INTO " . DB_TABLE . " (id, url, ip, count) VALUES (?, ?, ?, '0')");
$sth->bindParam(2, $url, PDO::PARAM_STR); $sth->bindParam(1, $hash, PDO::PARAM_STR, HASH_LENGTH);
$sth->bindParam(3, $clientip, PDO::PARAM_STR, 255); $sth->bindParam(2, $url, PDO::PARAM_STR);
if (!$sth->execute()) { $sth->bindParam(3, $clientip, PDO::PARAM_STR, 255);
$sth->execute();
} catch (PDOException $e) {
$hash = "ERROR<br />Failed to insert hash!"; $hash = "ERROR<br />Failed to insert hash!";
} }
} }