Added update method to database class

This commit is contained in:
2010-04-03 22:58:49 +01:00
parent df818037f2
commit 85f488bdb5

View File

@@ -52,7 +52,8 @@ class HandBrakeCluster_Database {
$result = $stmt->execute();
if (!$result) {
throw new HandBrakeCluster_Exception_DatabaseQueryFailed();
list($code, $dummy, $message) = $stmt->errorInfo();
throw new HandBrakeCluster_Exception_DatabaseQueryFailed($message, $code);
}
return $stmt->fetchAll();
@@ -83,17 +84,49 @@ class HandBrakeCluster_Database {
if ($bind_params) {
foreach ($bind_params as $param) {
if (isset($param['type'])) {
$stmt->bindValue(':'.$param['name'], $param['value'], $param['type']);
} else {
$stmt->bindValue(':'.$param['name'], $param['value']);
}
}
}
return $stmt->execute();
$result = $stmt->execute();
if (!$result) {
list($code, $dummy, $message) = $stmt->errorInfo();
throw new HandBrakeCluster_Exception_DatabaseQueryFailed($message, $code);
}
}
public function update($sql, $bind_params = null) {
$stmt = $this->dbh->prepare($sql);
if ($bind_params) {
foreach ($bind_params as $param) {
if (isset($param['type'])) {
$stmt->bindValue(':'.$param['name'], $param['value'], $param['type']);
} else {
$stmt->bindValue(':'.$param['name'], $param['value']);
}
}
}
$result = $stmt->execute();
if (!$result) {
list($code, $dummy, $message) = $stmt->errorInfo();
throw new HandBrakeCluster_Exception_DatabaseQueryFailed($message, $code);
}
}
public function errorInfo() {
return $this->dbh->errorInfo();
}
public function lastInsertId() {
return $this->dbh->lastInsertId();
}
}
?>