aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mekanisti.fi>2009-10-26 22:57:07 +0200
committerFilipp Lepalaan <filipp@mekanisti.fi>2009-10-26 22:57:07 +0200
commit730f91b3bab0767563184f99b40a851b6af6b635 (patch)
tree448f6ce52cfc39046773ebdd1a4f05cb39db1a17
parentc217e77f2540085922b4483c99670eca06923799 (diff)
parentb69995e1d0bcd5ea1185acfda4899e11f1d8e624 (diff)
downloadmain-730f91b3bab0767563184f99b40a851b6af6b635.tar.gz
main-730f91b3bab0767563184f99b40a851b6af6b635.tar.bz2
main-730f91b3bab0767563184f99b40a851b6af6b635.zip
Merge branch 'master' of github.com:filipp/main
Conflicts: Db.php
-rw-r--r--App.php13
-rw-r--r--Controller.php6
-rw-r--r--Db.php22
3 files changed, 31 insertions, 10 deletions
diff --git a/App.php b/App.php
index c8b93cf..686f92e 100644
--- a/App.php
+++ b/App.php
@@ -102,7 +102,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);
}
@@ -124,7 +126,13 @@ class App
}
$c = self::conf("app.error_log");
+
+ if (!$c) {
+ return false;
+ }
+
$file = realpath(__FILE__."/../../../../data/$c");
+
if (!$file) {
return false;
}
@@ -133,7 +141,10 @@ class App
fwrite($fh, trim($msg) . "\n");
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 6ab61df..84947b0 100644
--- a/Controller.php
+++ b/Controller.php
@@ -229,7 +229,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 = "";
@@ -278,7 +278,7 @@ class Controller
}
if (empty($data)) {
- exit(self::error("Update with empty parameters"));
+ return App::error("Update with empty parameters");
}
if (empty($where)) {
@@ -325,7 +325,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 4e5fe8a..7c9d4f8 100644
--- a/Db.php
+++ b/Db.php
@@ -22,7 +22,8 @@ class Db
{
$c = App::conf();
- if (!self::$instance) {
+ if (!self::$instance)
+ {
try {
self::$instance = new PDO(
"{$c['db.driver']}:host={$c['db.host']};dbname={$c['db.name']}",
@@ -65,18 +66,20 @@ class Db
}
try {
-
+
$stmt = self::getInstance()->prepare($sql);
$result = $stmt->execute($data);
if (!$result) {
- $e = $stmt->errorInfo();
- 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::error($error);
+ $error .= "\n" . print_r(debug_backtrace(), true);
+ return App::error($error);
}
// Select statements need the query results
@@ -88,7 +91,14 @@ class Db
$data['id'] = self::getInstance()->lastInsertId();
}
- return $data;
+ $out = array();
+ // Always strip ":" prefixes from input array keys
+ foreach ($data as $k => $v) {
+ $key = ltrim($k, ':');
+ $out[$key] = $v;
+ }
+
+ return $out;
}