From 11fade70ef96a3305ac98ba972c3fdf0662cfc77 Mon Sep 17 00:00:00 2001 From: Momchil Bozhinov Date: Tue, 23 Feb 2021 12:09:34 +0200 Subject: [PATCH] * Missed from refactoring pull --- php/clonos.php | 8 +++++--- php/db.php | 11 +++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/php/clonos.php b/php/clonos.php index c6acf6d0..7570a901 100644 --- a/php/clonos.php +++ b/php/clonos.php @@ -2492,10 +2492,12 @@ class ClonOS { [$this->form['pkg_vm_cpus']], [$owner] )); - if($res===false) return $this->messageError('sql error!'); - if(!$res['error']) return $this->messageSuccess($res); - return $this->messageError('sql error!',$res); + if($res['error'] == false){ + return $this->messageSuccess($res); + } else { + return $this->messageError('sql error!',$res); + } } function ccmd_vmTemplateEditInfo(){ diff --git a/php/db.php b/php/db.php index 30e1461e..dc189fcb 100644 --- a/php/db.php +++ b/php/db.php @@ -161,6 +161,7 @@ class Db { function insert($sql, $values){ try { + $this->_pdo->beginTransaction(); $query = $this->_pdo->prepare($sql); $i = 1; foreach($values as $v){ @@ -172,15 +173,19 @@ class Db { $i++; } $query->execute(); + $lastId = $this->_pdo->lastInsertId(); $this->_pdo->commit(); } catch(PDOException $e) { + $this->_pdo->rollBack(); + #throw new Exception($e->getMessage()); return array('error'=>true,'info'=>$e->getMessage()); } - return array('error'=>false,'lastID'=>$query->lastInsertId()); + return array('error'=>false,'lastID'=>$lastId); } function update($sql, $values){ try { + $this->_pdo->beginTransaction(); $query = $this->_pdo->prepare($sql); $i = 1; foreach($values as $v){ @@ -195,7 +200,9 @@ class Db { $rowCount=$query->rowCount(); $this->_pdo->commit(); } catch(PDOException $e) { - return false;//$e->getMessage(); + $this->_pdo->rollBack(); + #return false; + throw new Exception($e->getMessage()); } return array('rowCount'=>$rowCount); }