made exceptions from the db optional

set address for updae mails correctly
This commit is contained in:
Alexander Kampmann 2012-04-09 14:04:49 +02:00
parent 0d60dbef31
commit 7ac4b83c39
3 changed files with 930 additions and 884 deletions

1775
boot.php

File diff suppressed because it is too large Load diff

View file

@ -21,6 +21,8 @@ if(! class_exists('dba')) {
private $debug = 0; private $debug = 0;
private $db; private $db;
private $exceptions;
public $mysqli = true; public $mysqli = true;
public $connected = false; public $connected = false;
public $error = false; public $error = false;
@ -68,6 +70,10 @@ if(! class_exists('dba')) {
} }
} }
public function excep($excep) {
$this->exceptions=$excep;
}
public function getdb() { public function getdb() {
return $this->db; return $this->db;
} }
@ -75,7 +81,8 @@ if(! class_exists('dba')) {
public function q($sql) { public function q($sql) {
if((! $this->db) || (! $this->connected)) { 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) { if($this->mysqli) {
@ -114,7 +121,8 @@ if(! class_exists('dba')) {
} }
logger('dba: ' . $str ); logger('dba: ' . $str );
if(FALSE===$result) { 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() { public function beginTransaction() {
if($this->mysqli) { if($this->mysqli) {
return $this->db->autocommit(false); 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() { public function rollback() {
if($this->mysqli) { if($this->mysqli) {
return $this->db->rollback(); return $this->db->rollback();
@ -174,6 +199,9 @@ if(! class_exists('dba')) {
$this->stopTransaction(); $this->stopTransaction();
} }
/**
* commit a transaction. So, write any query to the database.
*/
public function commit() { public function commit() {
if($this->mysqli) { if($this->mysqli) {
return $this->db->commit(); return $this->db->commit();

View file

@ -11,7 +11,6 @@
* bootstrap the application * bootstrap the application
* *
*/ */
try {
require_once('boot.php'); require_once('boot.php');
@ -371,9 +370,3 @@ else
session_write_close(); session_write_close();
exit; exit;
} catch(Exception $ex) {
// it may fail because logger uses the db,
// but give it a try:
logger('exception caught at index.php: '.$ex->getMessage());
system_unavailable();
}