aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba.php
diff options
context:
space:
mode:
authorAlexander Kampmann <programmer@nurfuerspam.de>2012-04-09 14:04:49 +0200
committerAlexander Kampmann <programmer@nurfuerspam.de>2012-04-09 14:04:49 +0200
commit7ac4b83c39d841c80c39ca034971aaaa4bdf0e59 (patch)
tree6bd6979f4bfbce707c5d955f5036d2d269b68558 /include/dba.php
parent0d60dbef31ea645b8495d8e28fca6c248d20048b (diff)
downloadvolse-hubzilla-7ac4b83c39d841c80c39ca034971aaaa4bdf0e59.tar.gz
volse-hubzilla-7ac4b83c39d841c80c39ca034971aaaa4bdf0e59.tar.bz2
volse-hubzilla-7ac4b83c39d841c80c39ca034971aaaa4bdf0e59.zip
made exceptions from the db optional
set address for updae mails correctly
Diffstat (limited to 'include/dba.php')
-rw-r--r--include/dba.php32
1 files changed, 30 insertions, 2 deletions
diff --git a/include/dba.php b/include/dba.php
index cbf5922a7..8a9d599c4 100644
--- a/include/dba.php
+++ b/include/dba.php
@@ -21,6 +21,8 @@ if(! class_exists('dba')) {
private $debug = 0;
private $db;
+ private $exceptions;
+
public $mysqli = true;
public $connected = false;
public $error = false;
@@ -68,6 +70,10 @@ if(! class_exists('dba')) {
}
}
+ public function excep($excep) {
+ $this->exceptions=$excep;
+ }
+
public function getdb() {
return $this->db;
}
@@ -75,7 +81,8 @@ if(! class_exists('dba')) {
public function q($sql) {
if((! $this->db) || (! $this->connected)) {
- throw new RuntimeException(t("There is no db connection. "));
+ throwOrLog(new RuntimeException(t("There is no db connection. ")));
+ return;
}
if($this->mysqli) {
@@ -114,7 +121,8 @@ if(! class_exists('dba')) {
}
logger('dba: ' . $str );
if(FALSE===$result) {
- throw new RuntimeException('dba: ' . $str);
+ throwOrLog(new RuntimeException('dba: ' . $str));
+ return;
}
}
@@ -155,6 +163,19 @@ if(! class_exists('dba')) {
}
}
+ private function throwOrLog(Exception $ex) {
+ if($this->exceptions) {
+ throw $ex;
+ } else {
+ logger('dba: '.$ex->getMessage());
+ }
+ }
+
+ /**
+ * starts a transaction. Transactions need to be finished with
+ * commit() or rollback(). Please mind that the db table engine may
+ * not support this.
+ */
public function beginTransaction() {
if($this->mysqli) {
return $this->db->autocommit(false);
@@ -164,6 +185,10 @@ if(! class_exists('dba')) {
}
}
+ /**
+ * rollback a transaction. So, rollback anything that was done since the last call
+ * to beginTransaction().
+ */
public function rollback() {
if($this->mysqli) {
return $this->db->rollback();
@@ -174,6 +199,9 @@ if(! class_exists('dba')) {
$this->stopTransaction();
}
+ /**
+ * commit a transaction. So, write any query to the database.
+ */
public function commit() {
if($this->mysqli) {
return $this->db->commit();