svn: /web/presentations/trunk/slides/mvc/example/model/ items.inc
| From: | Rasmus Lerdorf | Date: | Mon, 23 May 2011 17:29:48 +0000 |
| Subject: | svn: /web/presentations/trunk/slides/mvc/example/model/ items.inc | ||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-1706@lists.php.net to get a copy of this message | ||
rasmus Mon, 23 May 2011 17:29:48 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=311358
Log:
Try to avoid db corruption here
Changed paths:
U web/presentations/trunk/slides/mvc/example/model/items.inc
Modified: web/presentations/trunk/slides/mvc/example/model/items.inc
===================================================================
--- web/presentations/trunk/slides/mvc/example/model/items.inc 2011-05-23 17:24:43 UTC (rev 311357)
+++ web/presentations/trunk/slides/mvc/example/model/items.inc 2011-05-23 17:29:48 UTC (rev 311358)
@@ -12,6 +12,7 @@
$t = $_SERVER["REQUEST_TIME"];
try {
if(!self::$dbh) $this->connect();
+ self::$dbh->beginTransaction();
$stmt = self::$dbh->prepare("INSERT INTO items
(id,cat,sdesc,ldesc,price,ctime)
VALUES
@@ -21,7 +22,9 @@
':ldesc'=>$item['ldesc'],
':price'=>$item['price']);
$ret = $stmt->execute($params);
+ self::$dbh->commit();
} catch (PDOException $e) {
+ self::$dbh->rollback();
$this->fatal_error($e->getMessage());
}
return $ret;
@@ -30,6 +33,7 @@
function modify($item) {
try {
if(!self::$dbh) $this->connect();
+ self::$dbh->beginTransaction();
$stmt = self::$dbh->prepare("UPDATE items SET
cat=:cat, sdesc=:sdesc,
ldesc=:ldesc, price=:price
@@ -40,7 +44,9 @@
':price'=>$item['price'],
':id'=>$item['id']);
$ret = $stmt->execute($params);
+ self::$dbh->commit();
} catch (PDOException $e) {
+ self::$dbh->rollback();
$this->fatal_error($e->getMessage());
}
return $ret;