Exception handling for INSERT
This commit is contained in:
parent
73c1957129
commit
d1f0b54ff5
12
index.php
12
index.php
|
@ -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!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue