DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
authorDan
Sun, 11 Jan 2009 21:36:36 -0500
changeset 809 ae4ef502f742
parent 808 97cd1a3229d0
child 810 7fd2b8a58ae4
DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
includes/dbal.php
--- a/includes/dbal.php	Sun Jan 11 21:35:39 2009 -0500
+++ b/includes/dbal.php	Sun Jan 11 21:36:36 2009 -0500
@@ -41,6 +41,7 @@
   var $row = array();
 	var $rowset = array();
   var $errhandler;
+  var $dbms_name = 'MySQL';
   
   function enable_errorhandler()
   {
@@ -105,7 +106,7 @@
   
   function die_json($loc = false)
   {
-    $e = addslashes(htmlspecialchars(mysql_error()));
+    $e = str_replace("\n", "\\n", addslashes(htmlspecialchars(mysql_error())));
     $q = str_replace("\n", "\\n", addslashes($this->latest_query));
     $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
     $loc .= "\n\nPlease report the full text of this error to the administrator of the site. If you believe that this is a bug with the software, please contact support@enanocms.org.";
@@ -771,6 +772,7 @@
   var $row = array();
 	var $rowset = array();
   var $errhandler;
+  var $dbms_name = 'PostgreSQL';
   
   function sql_backtrace()
   {
@@ -809,9 +811,12 @@
   
   function die_json()
   {
-    $e = addslashes(htmlspecialchars(pg_last_error()));
-    $q = addslashes($this->latest_query);
-    $t = "{'mode':'error','error':'An error occurred during database query.\nQuery was:\n  $q\n\nError returned by PostgreSQL: $e'}";
+    $e = str_replace("\n", "\\n", addslashes(htmlspecialchars(pg_last_error())));
+    $q = str_replace("\n", "\\n", addslashes($this->latest_query));
+    $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
+    $loc .= "\n\nPlease report the full text of this error to the administrator of the site. If you believe that this is a bug with the software, please contact support@enanocms.org.";
+    $loc = str_replace("\n", "\\n", $loc);
+    $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by MySQL: $e$loc\"}";
     die($t);
   }