Changeset:
        1e6287dc667c
        
https://sourceforge.net/p/mrbs/hg-code/ci/1e6287dc667c76b261d7b367b5abbcb117f6f084
Author:
        Campbell Morrison <[email protected]>
Date:
        Wed Sep 28 18:07:00 2016 +0100
Log message:

Added SQL information

diffstat:

 web/functions_error.inc      |   1 +
 web/lib/MRBS/DB.php          |  11 +++++++++--
 web/lib/MRBS/DBException.php |  16 ++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diffs (52 lines):

diff -r 335c4cdbb935 -r 1e6287dc667c web/functions_error.inc
--- a/web/functions_error.inc   Wed Sep 28 17:07:02 2016 +0100
+++ b/web/functions_error.inc   Wed Sep 28 18:07:00 2016 +0100
@@ -46,6 +46,7 @@
   
   switch ($class)
   {
+    case __NAMESPACE__ . "\\DBException":
     case 'PDOException':
       $message = get_vocab("fatal_db_error");
       break;
diff -r 335c4cdbb935 -r 1e6287dc667c web/lib/MRBS/DB.php
--- a/web/lib/MRBS/DB.php       Wed Sep 28 17:07:02 2016 +0100
+++ b/web/lib/MRBS/DB.php       Wed Sep 28 18:07:00 2016 +0100
@@ -179,8 +179,15 @@
   // Returns FALSE on error; use error() to get the error message.
   public function query ($sql, $params = array())
   {
-    $sth = $this->dbh->prepare($sql);
-    $sth->execute($params);
+    try
+    {
+      $sth = $this->dbh->prepare($sql);
+      $sth->execute($params);
+    }
+    catch (PDOException $e)
+    {
+      throw new DBException($e->getMessage(), 0, $e, $sql, $params);
+    }
   
     return new DBStatement($this, $sth);
   }
diff -r 335c4cdbb935 -r 1e6287dc667c web/lib/MRBS/DBException.php
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/web/lib/MRBS/DBException.php      Wed Sep 28 18:07:00 2016 +0100
@@ -0,0 +1,16 @@
+<?php
+namespace MRBS;
+
+class DBException extends \PDOException
+{
+  
+  public function __construct($message, $code=0, \PDOException $previous=null, 
$sql=null, $params=null)
+  {
+    $message = $message . "\n" .
+               'SQL: ' . str_replace("\n", '', $sql) . "\n" .
+               'Params: ' . print_r($params, true);
+               
+    parent::__construct($message, $code, $previous);
+  }
+  
+}

------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to