From 85f488bdb5036b65b5607c6ad3e33abfcc619e49 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sat, 3 Apr 2010 22:58:49 +0100 Subject: [PATCH] Added update method to database class --- HandBrakeCluster/Database.class.php | 39 ++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/HandBrakeCluster/Database.class.php b/HandBrakeCluster/Database.class.php index 5f2075a..e2deff3 100644 --- a/HandBrakeCluster/Database.class.php +++ b/HandBrakeCluster/Database.class.php @@ -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,16 +84,48 @@ class HandBrakeCluster_Database { if ($bind_params) { foreach ($bind_params as $param) { - $stmt->bindValue(':'.$param['name'], $param['value'], $param['type']); + 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(); + } }