Skip to content

Instantly share code, notes, and snippets.

@jtnix
Created April 2, 2018 19:24
Show Gist options
  • Save jtnix/46cdae01ba03b96d1dbe047e192784d8 to your computer and use it in GitHub Desktop.
Save jtnix/46cdae01ba03b96d1dbe047e192784d8 to your computer and use it in GitHub Desktop.
Improved PDO Exception messaging
Index: library/Zend/Db/Statement/Pdo.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- library/Zend/Db/Statement/Pdo.php (revision 4524)
+++ library/Zend/Db/Statement/Pdo.php (revision )
@@ -231,7 +231,12 @@
}
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
- throw new Zend_Db_Statement_Exception($e->getMessage(), (int) $e->getCode(), $e);
+ $msg = "SQL ERROR: ". $e->getMessage() . "\n";
+ $msg .= "SQL QUERY:" . $this->_stmt->queryString."\n";
+ if(!empty($params)) {
+ $msg .= "SQL PARAMS: ('". implode("','", $params) ."')\n";
+ }
+ throw new Zend_Db_Statement_Exception($msg, (int) $e->getCode(), $e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment