includes/dbal.php
changeset 879 9788f2b7e08a
parent 860 c931041e689a
child 902 e7c6f1aa7b6a
equal deleted inserted replaced
878:ecc764c10138 879:9788f2b7e08a
   827     $e = str_replace("\n", "\\n", addslashes(htmlspecialchars(pg_last_error())));
   827     $e = str_replace("\n", "\\n", addslashes(htmlspecialchars(pg_last_error())));
   828     $q = str_replace("\n", "\\n", addslashes($this->latest_query));
   828     $q = str_replace("\n", "\\n", addslashes($this->latest_query));
   829     $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
   829     $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
   830     $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.";
   830     $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.";
   831     $loc = str_replace("\n", "\\n", $loc);
   831     $loc = str_replace("\n", "\\n", $loc);
   832     $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by MySQL: $e$loc\"}";
   832     $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
   833     die($t);
   833     die($t);
   834   }
   834   }
   835   
   835   
   836   function get_error($t = '') {
   836   function get_error($t = '') {
   837     @header('HTTP/1.1 500 Internal Server Error');
   837     @header('HTTP/1.1 500 Internal Server Error');
   841     global $email;
   841     global $email;
   842     $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) ) ? ', at <' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '>' : '';
   842     $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) ) ? ', at <' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '>' : '';
   843     $internal_text = '<h3>The site was unable to finish serving your request.</h3>
   843     $internal_text = '<h3>The site was unable to finish serving your request.</h3>
   844                       <p>We apologize for the inconveience, but an error occurred in the Enano database layer. Please report the full text of this page to the administrator of this site' . $email_info . '.</p>
   844                       <p>We apologize for the inconveience, but an error occurred in the Enano database layer. Please report the full text of this page to the administrator of this site' . $email_info . '.</p>
   845                       <p>Description or location of error: '.$t.'<br />
   845                       <p>Description or location of error: '.$t.'<br />
   846                       Error returned by MySQL extension: ' . $e . '<br />
   846                       Error returned by ' . $this->dbms_name . ' extension: ' . $e . '<br />
   847                       Most recent SQL query:</p>
   847                       Most recent SQL query:</p>
   848                       <pre>'.$bt.'</pre>';
   848                       <pre>'.$bt.'</pre>';
   849     return $internal_text;
   849     return $internal_text;
   850   }
   850   }
   851   
   851   
  1023   }
  1023   }
  1024   
  1024   
  1025   /**
  1025   /**
  1026    * Set the internal result pointer to X
  1026    * Set the internal result pointer to X
  1027    * @param int $pos The number of the row
  1027    * @param int $pos The number of the row
  1028    * @param resource $result The MySQL result resource - if not given, the latest cached query is assumed
  1028    * @param resource $result The PostgreSQL result resource - if not given, the latest cached query is assumed
  1029    * @return true on success, false on failure
  1029    * @return true on success, false on failure
  1030    */
  1030    */
  1031    
  1031    
  1032   function sql_data_seek($pos, $result = false)
  1032   function sql_data_seek($pos, $result = false)
  1033   {
  1033   {
  1125   }
  1125   }
  1126   
  1126   
  1127   function fetchrow($r = false) {
  1127   function fetchrow($r = false) {
  1128     if(!$this->_conn) return false;
  1128     if(!$this->_conn) return false;
  1129     if(!$r) $r = $this->latest_result;
  1129     if(!$r) $r = $this->latest_result;
  1130     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
  1130     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1131     $row = pg_fetch_assoc($r);
  1131     $row = pg_fetch_assoc($r);
  1132     return integerize_array($row);
  1132     return integerize_array($row);
  1133   }
  1133   }
  1134   
  1134   
  1135   function fetchrow_num($r = false) {
  1135   function fetchrow_num($r = false) {
  1136     if(!$r) $r = $this->latest_result;
  1136     if(!$r) $r = $this->latest_result;
  1137     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
  1137     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1138     $row = pg_fetch_row($r);
  1138     $row = pg_fetch_row($r);
  1139     return integerize_array($row);
  1139     return integerize_array($row);
  1140   }
  1140   }
  1141   
  1141   
  1142   function numrows($r = false) {
  1142   function numrows($r = false) {
  1143     if(!$r) $r = $this->latest_result;
  1143     if(!$r) $r = $this->latest_result;
  1144     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
  1144     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1145     $n = pg_num_rows($r);
  1145     $n = pg_num_rows($r);
  1146     return $n;
  1146     return $n;
  1147   }
  1147   }
  1148   
  1148   
  1149   function escape($str)
  1149   function escape($str)
  1176   }
  1176   }
  1177   function sql_freeresult($r = false)
  1177   function sql_freeresult($r = false)
  1178   {
  1178   {
  1179     if(!$this->_conn) return false;
  1179     if(!$this->_conn) return false;
  1180     if(!$r) $r = $this->latest_result;
  1180     if(!$r) $r = $this->latest_result;
  1181     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
  1181     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1182     $this->free_result($r);
  1182     $this->free_result($r);
  1183   }
  1183   }
  1184   function sql_numrows($r = false)
  1184   function sql_numrows($r = false)
  1185   {
  1185   {
  1186     return $this->numrows();
  1186     return $this->numrows();
  1187   }
  1187   }
  1188   function sql_affectedrows($r = false, $f, $n)
  1188   function sql_affectedrows($r = false, $f, $n)
  1189   {
  1189   {
  1190     if(!$this->_conn) return false;
  1190     if(!$this->_conn) return false;
  1191     if(!$r) $r = $this->latest_result;
  1191     if(!$r) $r = $this->latest_result;
  1192     if(!$r) $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
  1192     if(!$r) $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
  1193     return pg_affected_rows();
  1193     return pg_affected_rows();
  1194   }
  1194   }
  1195   
  1195   
  1196   function sql_type_cast(&$value)
  1196   function sql_type_cast(&$value)
  1197 	{
  1197 	{