aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--App.php15
-rw-r--r--Controller.php6
-rw-r--r--Db.php13
3 files changed, 24 insertions, 10 deletions
diff --git a/App.php b/App.php
index ec26b58..1978d29 100644
--- a/App.php
+++ b/App.php
@@ -109,7 +109,9 @@ class App
static function error($msg)
{
$err = array('result' => 'error', 'msg' => $msg);
+ // Send error to client
self::json($msg);
+ // And log it locally
self::log($msg);
}
@@ -121,16 +123,27 @@ class App
if (is_array($msg)) {
$msg = print_r($msg, true);
}
+
$c = self::conf("app.error_log");
+
+ if (!$c) {
+ return false;
+ }
+
$file = realpath(__FILE__."/../../../../data/$c");
+
if (!$file) {
return false;
}
+
$fh = fopen($file, "a+");
fwrite($fh, $msg);
fclose($fh);
}
-
+
+ /**
+ * Set our own PHP error handler
+ */
static function error_handler($errno, $errstr, $errfile, $errline)
{
$str = sprintf("%s\t%s\t%s\t%s\n", date("d.m @ H:i:s"), basename($errfile), $errline, $errstr);
diff --git a/Controller.php b/Controller.php
index 8f8bbd8..d5813a1 100644
--- a/Controller.php
+++ b/Controller.php
@@ -224,7 +224,7 @@ class Controller
if (empty($data)) {
App::log("Attempted to insert empty data");
- exit(App::error("Insert failed - nothing to insert"));
+ return App::error("Nothing to insert");
}
$insert = "";
@@ -273,7 +273,7 @@ class Controller
}
if (empty($data)) {
- exit(self::error("Update with empty parameters"));
+ return App::error("Update with empty parameters");
}
if (empty($where)) {
@@ -320,7 +320,7 @@ class Controller
$file = "../system/views/{$this->table}/{$view}.{$type}";
if (!is_file($file)) {
- exit(App::error("{$this->table}_{$view}_{$type}: no such view"));
+ return App::error("{$this->table}_{$view}_{$type}: no such view");
}
if ($data) {
diff --git a/Db.php b/Db.php
index e90362f..2b66fbe 100644
--- a/Db.php
+++ b/Db.php
@@ -66,19 +66,20 @@ class Db
}
try {
-
+
$stmt = self::getInstance()->prepare($sql);
$result = $stmt->execute($data);
if (!$result) {
- $e = $stmt->errorInfo();
- exit(App::error($e[2]));
+ $e = $pdo->errorInfo();
+ $error = $e[2] ."\n" . print_r(debug_backtrace(), true);
+ return App::error($error);
}
} catch (PDOException $e) {
$error = $e->getMessage() . $sql;
- App::log($error);
- exit(App::error($error));
+ $error .= "\n" . print_r(debug_backtrace(), true);
+ return App::error($error);
}
// Select statements need the query results
@@ -90,8 +91,8 @@ class Db
$data['id'] = self::getInstance()->lastInsertId();
}
- // Always strip ":" prefixes from input array keys
$out = array();
+ // Always strip ":" prefixes from input array keys
foreach ($data as $k => $v) {
$key = ltrim($k, ':');
$out[$key] = $v;