includes/dbal.php
author Dan
Sun, 13 Dec 2009 03:56:06 -0500
changeset 1165 ce8aaa2956d1
parent 1147 7ddd475bc661
child 1175 1e2c9819ede3
permissions -rw-r--r--
DBAL: Majorly cleaned up and improved coding standards/documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     2
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
/*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 973
diff changeset
     5
 * Copyright (C) 2006-2009 Dan Fuhry
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     6
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
function db_error_handler($errno, $errstr, $errfile = false, $errline = false, $errcontext = Array() )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    15
{
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    16
  if ( !defined('ENANO_DEBUG') )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    17
    return;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    18
  $e = error_reporting(0);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    19
  error_reporting($e);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    20
  if ( $e < $errno )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    21
    return;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    22
  $errtype = 'Notice';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    23
  switch ( $errno )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    24
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    25
    case E_ERROR: case E_USER_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: $errtype = 'Error'; break;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    26
    case E_WARNING: case E_USER_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: $errtype = 'Warning'; break;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    27
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    28
  $debug = debug_backtrace();
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    29
  if ( !isset($debug[0]['file']) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    30
    return false;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    31
  $debug = $debug[0]['file'] . ', line ' . $debug[0]['line'];
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    32
  echo "<b>$errtype:</b> $errstr<br />Error source:<pre>$debug</pre>";
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    33
}
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    34
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    35
global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    36
$db_sql_parse_time = 0;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    37
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    38
class mysql {
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    39
  var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    40
  var $row = array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    41
	var $rowset = array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    42
  var $errhandler;
809
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
    43
  var $dbms_name = 'MySQL';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    44
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    45
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    46
   * Get a flat textual list of queries that have been made.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    47
   */
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    48
  
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    49
  function sql_backtrace()
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    50
  {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    51
    return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    53
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    54
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    55
   * Connect to the database, but only if a connection isn't already up.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    56
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    57
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    58
  function ensure_connection()
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    59
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    60
    if(!$this->_conn)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    62
      $this->connect();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    63
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    64
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    65
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    66
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    67
   * Exit Enano, dumping out a friendly error message indicating a database error on the way out.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    68
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    69
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    70
 
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    71
  function _die($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    72
  {
940
645727469415 DBAL: _die() now detects installation environment and, if present, calls installer UI library for error display chrome
Dan
parents: 902
diff changeset
    73
    if ( defined('ENANO_HEADERS_SENT') )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    74
      ob_clean();
940
645727469415 DBAL: _die() now detects installation environment and, if present, calls installer UI library for error display chrome
Dan
parents: 902
diff changeset
    75
    
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    76
    $internal_text = $this->get_error($t);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    77
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    78
    if ( defined('ENANO_CONFIG_FETCHED') )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    79
      // config is in, we can show a slightly nicer looking error page
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    80
      die_semicritical('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    81
    else
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    82
      // no config, display using no-DB template engine
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    83
      grinding_halt('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    84
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    85
    exit;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    86
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    87
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    88
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    89
   * Get the internal text used for a database error message.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    90
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    91
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    92
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    93
  function get_error($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    94
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    95
    @header('HTTP/1.1 500 Internal Server Error');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    96
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    97
    $bt = $this->latest_query;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    98
    $e = htmlspecialchars($this->sql_error());
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    99
    if ( empty($e) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   100
      $e = '&lt;none&gt;';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   101
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   102
    global $email;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   103
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   104
    // As long as the admin's e-mail is accessible, display it.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   105
    $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   106
                    ? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   107
                    : '';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   108
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   109
    $internal_text = "<h3>The site was unable to finish serving your request.</h3>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   110
                      <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>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   111
                      <p>Description or location of error: $t<br />
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   112
                      Error returned by $this->dbms_name extension: $e</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   113
                      <p>Most recent SQL query:</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   114
                      <pre>$bt</pre>";
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   115
    return $internal_text;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   116
  }
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   117
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   118
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   119
   * Exit Enano and output a JSON format datbase error.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   120
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   121
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   122
  
475
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   123
  function die_json($loc = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   124
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   125
    $e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
468
194a19711346 Fixed the fact that cron just didn't work at all (brain fart that day or something)
Dan
parents: 424
diff changeset
   126
    $q = str_replace("\n", "\\n", addslashes($this->latest_query));
475
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   127
    $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   128
    $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.";
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   129
    $loc = str_replace("\n", "\\n", $loc);
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   130
    $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   131
    die($t);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   132
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   133
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   134
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   135
   * Connect to the database.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   136
   * @param bool If true, enables all other parameters. Defaults to false, which emans that you can call this function with no arguments and it will fetch information from the config file.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   137
   * @param string Database server hostname
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   138
   * @param string Database server username
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   139
   * @param string Database server password
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   140
   * @param string Name of the database
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   141
   * @param int Optional port number to connect over
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   142
   */
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   143
  
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   144
  function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   145
  {
483
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   146
    if ( !defined('ENANO_SQL_CONSTANTS') )
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   147
    {
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   148
      define('ENANO_SQL_CONSTANTS', '');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   149
      define('ENANO_DBLAYER', 'MYSQL');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   150
      define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   151
      define('ENANO_SQL_MULTISTRING_PRFIX', '');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   152
      define('ENANO_SQL_BOOLEAN_TRUE', 'true');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   153
      define('ENANO_SQL_BOOLEAN_FALSE', 'false');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   154
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   155
    
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   156
    if ( !$manual_credentials )
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   157
    {
1143
e271ae801c62 common_cli and dbal: Fixed lack of ENANO_INSTALLED check in determining config path
Dan
parents: 1081
diff changeset
   158
      if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') && !defined('ENANO_INSTALLED') )
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   159
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   160
        @include(ENANO_ROOT.'/config.new.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   161
      }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   162
      else
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   163
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   164
        @include(ENANO_ROOT.'/config.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   165
      }
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   166
      
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   167
      if ( isset($crypto_key) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   168
        unset($crypto_key); // Get this sucker out of memory fast
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   169
      if ( empty($dbport) )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   170
        $dbport = 3306;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   171
      
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   172
      if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
272
e0ec986c0af3 Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents: 268
diff changeset
   173
      {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   174
        // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   175
        if ( !defined('scriptPath') )
272
e0ec986c0af3 Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents: 268
diff changeset
   176
        {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   177
          if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   178
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   179
            $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   180
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   181
          if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   182
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   183
            // user requested http://foo/enano as opposed to http://foo/enano/index.php
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   184
            $_SERVER['REQUEST_URI'] .= '/index.php';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   185
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   186
          $sp = dirname($_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   187
          if($sp == '/' || $sp == '\\') $sp = '';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   188
          define('scriptPath', $sp);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   189
          define('contentPath', "$sp/index.php?title=");
288
9a1a32bc2050 Hopefully once again fix scriptPath detection in dbal.php
Dan
parents: 286
diff changeset
   190
        }
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   191
        $loc = scriptPath . '/install/index.php';
331
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   192
        define('IN_ENANO_INSTALL', 1);
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   193
        $GLOBALS['lang'] = new Language('eng');
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   194
        global $lang;
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   195
        $lang->load_file('./language/english/core.json');
331
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   196
        $lang->load_file('./language/english/install.json');
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   197
        // header("Location: $loc");
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   198
        redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 0);
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   199
        exit;
272
e0ec986c0af3 Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents: 268
diff changeset
   200
      }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   201
    }
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   202
    
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   203
    if ( !$dbport )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   204
      $dbport = 3306;
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   205
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   206
    if ( $dbhost && !empty($dbport) && $dbport != 3306 )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   207
      $dbhost = '127.0.0.1';
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   208
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   209
    $host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   210
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   211
    $this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   212
    unset($dbuser);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   213
    unset($dbpasswd); // Security
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   214
    
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   215
    if ( !$this->_conn && !$manual_credentials )
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   216
    {
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   217
      grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to MySQL.<br />'.mysql_error().'</p>');
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   218
    }
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   219
    else if ( !$this->_conn && $manual_credentials )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   220
    {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   221
      return false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   222
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   223
    
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   224
    // Reset some variables
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   225
    $this->query_backtrace = array();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   226
    $this->query_times = array();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   227
    $this->query_sources = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   228
    $this->num_queries = 0;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   229
    
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   230
    $this->debug = ( defined('ENANO_DEBUG') );
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   231
    
973
451141c834fe Replaced the USE with a mysql_select_db() to cut out one query
Dan
parents: 953
diff changeset
   232
    $q = @mysql_select_db($dbname);
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   233
    
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   234
    if ( !$q )
352
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   235
    {
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   236
      if ( $manual_credentials )
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   237
        return false;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   238
      $this->_die('The database could not be selected.');
352
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   239
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   240
    
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   241
    // We're in!
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   242
    return true;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   243
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   244
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   245
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   246
   * Make a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   247
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   248
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   249
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   250
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   251
  
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   252
  function sql_query($q, $log_query = true)
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   253
  {
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   254
    if ( $this->debug && function_exists('debug_backtrace') )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   255
    {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   256
      $backtrace = @debug_backtrace();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   257
      if ( is_array($backtrace) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   258
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   259
        $bt = $backtrace[0];
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   260
        if ( isset($backtrace[1]['class']) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   261
        {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   262
          if ( $backtrace[1]['class'] == 'sessionManager' )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   263
          {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   264
            $bt = $backtrace[1];
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   265
          }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   266
        }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   267
        $this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   268
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   269
      unset($backtrace);
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   270
    }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   271
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   272
    $this->num_queries++;
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   273
    if ( $log_query || defined('ENANO_DEBUG') )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   274
    {
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   275
      $this->query_backtrace[] = $q;
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   276
      $this->latest_query = $q;
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   277
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   278
    // First make sure we have a connection
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   279
    if ( !$this->_conn )
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   280
    {
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   281
      $this->_die('A database connection has not yet been established.');
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   282
    }
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   283
    // Start the timer
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   284
    if ( $log_query || defined('ENANO_DEBUG') )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   285
      $time_start = microtime_float();
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   286
    // Does this query look malicious?
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   287
    if ( $log_query || defined('ENANO_DEBUG') )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   288
    {
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   289
      if ( !$this->check_query($q) )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   290
      {
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   291
        $this->report_query($q);
681
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   292
        $debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   293
        grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p>' . $debug);
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   294
      }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   295
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   296
    
619
80fa6fa6bf3a Oops, somehow changed mysql_query() to pg_query() in MySQL DBAL
Dan
parents: 616
diff changeset
   297
    $r = mysql_query($q, $this->_conn);
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   298
    
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   299
    if ( $log_query )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   300
      $this->query_times[$q] = microtime_float() - $time_start;
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   301
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   302
    $this->latest_result = $r;
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   303
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   304
    return $r;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   305
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   306
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   307
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   308
   * Make a SQL query, but do not have PHP buffer all the results. Useful for queries that are expected to return a huge number of results.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   309
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   310
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   311
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   312
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   313
  
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   314
  function sql_unbuffered_query($q, $log_query = true)
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   315
  {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   316
    $this->num_queries++;
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   317
    if ( $log_query || defined('ENANO_DEBUG') )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   318
      $this->query_backtrace[] = '(UNBUFFERED) ' . $q;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   319
    $this->latest_query = $q;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   320
    // First make sure we have a connection
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   321
    if ( !$this->_conn )
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   322
    {
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   323
      $this->_die('A database connection has not yet been established.');
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   324
    }
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   325
    // Does this query look malicious?
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   326
    if ( !$this->check_query($q) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   327
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   328
      $this->report_query($q);
681
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   329
      $debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   330
      grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p>' . $debug);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   331
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   332
    
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   333
    $time_start = microtime_float();
681
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   334
    $r = @mysql_unbuffered_query($q, $this->_conn);
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   335
    $this->query_times[$q] = microtime_float() - $time_start;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   336
    $this->latest_result = $r;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   337
    return $r;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   338
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   339
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   340
  /**
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   341
   * Performs heuristic analysis on a SQL query to check for known attack patterns.
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   342
   * @param string $q the query to check
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   343
   * @return bool true if query passed check, otherwise false
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   344
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   345
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   346
  function check_query($q, $debug = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   347
  {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   348
    global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   349
    $ts = microtime_float();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   350
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   351
    // remove properly escaped quotes
812
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   352
    $q = str_replace('\\\\', '', $q);
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   353
    $q = str_replace(array("\\\"", "\\'"), '', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   354
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   355
    // make sure quotes match
616
e311f5e6f904 Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents: 592
diff changeset
   356
    foreach ( array("'", '"') as $quote )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   357
    {
812
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   358
      $n_quotes = get_char_count($q, $quote);
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   359
      if ( $n_quotes % 2 == 1 )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   360
      {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   361
        // mismatched quotes
812
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   362
        if ( $debug ) echo "Found mismatched quotes in query; parsed:\n$q\n";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   363
        return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   364
      }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   365
      // this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   366
      $q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   367
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   368
    $q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   369
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   370
    // quotes are now matched out. does this string have a comment marker in it?
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   371
    if ( strstr($q, '--') )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   372
    {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   373
      return false;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   374
    }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   375
    
128
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   376
    if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   377
    {
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   378
      if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   379
      return false;
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   380
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   381
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   382
    $ts = microtime_float() - $ts;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   383
    $db_sql_parse_time += $ts;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   384
    return true;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   385
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   386
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   387
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   388
   * Set the internal result pointer to X
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   389
   * @param int $pos The number of the row
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   390
   * @param resource $result The MySQL result resource - if not given, the latest cached query is assumed
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   391
   * @return true on success, false on failure
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   392
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   393
   
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   394
  function sql_data_seek($pos, $result = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   395
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   396
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   397
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   398
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   399
      return false;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   400
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   401
    return mysql_data_seek($result, $pos) ? true : false;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   402
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   403
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   404
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   405
   * Reports a bad query to the admin
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   406
   * @param string $query the naughty query
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   407
   * @access private
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   408
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   409
   
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   410
  function report_query($query)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   411
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   412
    global $session;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   413
    if ( is_object($session) && defined('ENANO_MAINSTREAM') )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   414
      $username = $session->username;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   415
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   416
      $username = 'Unavailable';
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   417
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   418
    $query = $this->escape($query);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   419
    $q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            edit_summary)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   420
                                                     VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', \''.$_SERVER['REMOTE_ADDR'].'\');');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   421
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   422
  
73
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   423
  /**
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   424
   * Returns the ID of the row last inserted.
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   425
   * @return int
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   426
   */
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   427
  
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   428
  function insert_id()
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   429
  {
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   430
    return @mysql_insert_id();
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   431
  }
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   432
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   433
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   434
   * Fetch one row from the given query as an associative array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   435
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   436
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   437
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   438
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   439
  function fetchrow($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   440
  {
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   441
    if ( !$this->_conn )
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   442
      return false;
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   443
    
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   444
    if ( !$r )
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   445
      $r = $this->latest_result;
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   446
    
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   447
    if ( !$r )
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   448
      $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   449
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   450
    $row = mysql_fetch_assoc($r);
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   451
    
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
   452
    return integerize_array($row);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   453
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   454
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   455
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   456
   * Fetch one row from the given query as a numeric array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   457
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   458
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   459
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   460
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   461
  function fetchrow_num($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   462
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   463
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   464
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   465
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   466
      $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   467
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   468
    $row = mysql_fetch_row($r);
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
   469
    return integerize_array($row);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   470
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   471
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   472
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   473
   * Get the number of results for a given query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   474
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   475
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   476
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   477
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   478
  function numrows($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   479
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   480
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   481
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   482
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   483
      $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   484
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   485
    return mysql_num_rows($r);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   486
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   487
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   488
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   489
   * Escape a string so that it may safely be included in a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   490
   * @param string String to escape
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   491
   * @return string Escaped string
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   492
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   493
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   494
  function escape($str)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   495
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   496
    $str = mysql_real_escape_string($str);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   497
    return $str;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   498
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   499
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   500
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   501
   * Free the given result from memory. Use this when completely finished with a result resource.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   502
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   503
   * @return null
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   504
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   505
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   506
  function free_result($result = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   507
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   508
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   509
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   510
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   511
      return null;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   512
    
374
5c740e430a05 [minor] silenced errors to mysql_free_result() and pg_free_result()
Dan
parents: 352
diff changeset
   513
    @mysql_free_result($result);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   514
    return null;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   515
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   516
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   517
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   518
   * Close the database connection
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   519
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   520
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   521
  function close()
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   522
  {
503
f205f4b201ed [minor] silence errors when closing DB connections
Dan
parents: 483
diff changeset
   523
    @mysql_close($this->_conn);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   524
    unset($this->_conn);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   525
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   526
  
1147
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   527
  /**
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   528
   * Get a list of columns in the given table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   529
   * @param string Table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   530
   * @return array
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   531
   */
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   532
  
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   533
  function columns_in($table)
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   534
  {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   535
    if ( !is_string($table) )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   536
      return false;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   537
    $q = $this->sql_query("SHOW COLUMNS IN $table;");
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   538
    if ( !$q )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   539
      $this->_die();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   540
    
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   541
    $columns = array();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   542
    while ( $row = $this->fetchrow_num() )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   543
    {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   544
      $columns[] = $row[0];
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   545
    }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   546
    return $columns;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   547
  }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   548
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   549
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   550
   * Get the text of the most recent error.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   551
   * @return string
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   552
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   553
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   554
  function sql_error()
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   555
	{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   556
    return mysql_error();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   557
	}
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   558
  
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   559
  /**
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   560
   * Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   561
   */
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   562
  
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   563
  function sql_report()
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   564
  {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   565
    global $db, $session, $paths, $template, $plugins; // Common objects
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   566
    if ( !$session->get_permissions('mod_misc') )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   567
    {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   568
      die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   569
    }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   570
    // Create copies of variables that may be changed after header is called
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   571
    $backtrace = $this->query_backtrace;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   572
    $times = $this->query_times;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   573
    $template->header();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   574
    echo '<h3>SQL query log and timetable</h3>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   575
    echo '<div class="tblholder">
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   576
            <table border="0" cellspacing="1" cellpadding="4">';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   577
    $i = 0;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   578
    foreach ( $backtrace as $query )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   579
    {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   580
      $i++;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   581
      $unbuffered = false;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   582
      if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   583
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   584
        $query = substr($query, 13);
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   585
        $unbuffered = true;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   586
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   587
      if ( $i == 1 )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   588
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   589
        echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   590
                <th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   591
              </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   592
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   593
      else
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   594
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   595
        echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   596
                <th class="subhead" colspan="2">&nbsp;</th>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   597
              </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   598
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   599
      echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   600
              <td class="row2">Query:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   601
              <td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   602
            </tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   603
            <tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   604
              <td class="row2">Time:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   605
              <td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   606
            </tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   607
            <tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   608
              <td class="row2">Unbuffered:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   609
              <td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   610
            </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   611
      if ( isset($this->query_sources[$query]) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   612
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   613
        echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   614
                <td class="row2">Called from:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   615
                <td class="row1">' . $this->query_sources[$query] . '</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   616
              </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   617
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   618
    }
293
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   619
    if ( function_exists('array_sum') )
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   620
    {
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   621
      $query_time_total = array_sum($this->query_times);
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   622
      echo '<tr>
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   623
              <th class="subhead" colspan="2">
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   624
                Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   625
              </th>
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   626
            </tr>';
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   627
    }
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   628
    echo '  </table>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   629
          </div>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   630
    $template->footer();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   631
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   632
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   633
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   634
class postgresql
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   635
{
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   636
  var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   637
  var $row = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   638
	var $rowset = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   639
  var $errhandler;
809
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   640
  var $dbms_name = 'PostgreSQL';
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   641
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   642
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   643
   * Get a flat textual list of queries that have been made.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   644
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   645
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   646
  function sql_backtrace()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   647
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   648
    return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   649
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   650
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   651
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   652
   * Connect to the database, but only if a connection isn't already up.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   653
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   654
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   655
  function ensure_connection()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   656
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   657
    if(!$this->_conn)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   658
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   659
      $this->connect();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   660
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   661
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   662
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   663
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   664
   * Exit Enano, dumping out a friendly error message indicating a database error on the way out.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   665
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   666
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   667
 
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   668
  function _die($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   669
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   670
    if ( defined('ENANO_HEADERS_SENT') )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   671
      ob_clean();
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   672
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   673
    $internal_text = $this->get_error($t);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   674
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   675
    if ( defined('ENANO_CONFIG_FETCHED') )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   676
      // config is in, we can show a slightly nicer looking error page
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   677
      die_semicritical('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   678
    else
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   679
      // no config, display using no-DB template engine
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   680
      grinding_halt('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   681
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   682
    exit;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   683
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   684
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   685
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   686
   * Get the internal text used for a database error message.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   687
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   688
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   689
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   690
  function get_error($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   691
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   692
    @header('HTTP/1.1 500 Internal Server Error');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   693
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   694
    $bt = $this->latest_query;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   695
    $e = htmlspecialchars($this->sql_error());
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   696
    if ( empty($e) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   697
      $e = '&lt;none&gt;';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   698
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   699
    global $email;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   700
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   701
    // As long as the admin's e-mail is accessible, display it.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   702
    $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   703
                    ? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   704
                    : '';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   705
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   706
    $internal_text = "<h3>The site was unable to finish serving your request.</h3>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   707
                      <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>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   708
                      <p>Description or location of error: $t<br />
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   709
                      Error returned by $this->dbms_name extension: $e</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   710
                      <p>Most recent SQL query:</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   711
                      <pre>$bt</pre>";
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   712
    return $internal_text;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   713
  }
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   714
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   715
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   716
   * Exit Enano and output a JSON format datbase error.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   717
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   718
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   719
  
860
c931041e689a DBAL: Fixed missing $loc in pgsql die_json()
Dan
parents: 857
diff changeset
   720
  function die_json($loc = false)
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   721
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   722
    $e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
809
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   723
    $q = str_replace("\n", "\\n", addslashes($this->latest_query));
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   724
    $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   725
    $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.";
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   726
    $loc = str_replace("\n", "\\n", $loc);
879
9788f2b7e08a Corrected a few display issues in Postgres DBAL. Thanks Neal.
Dan
parents: 860
diff changeset
   727
    $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   728
    die($t);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   729
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   730
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   731
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   732
   * Connect to the database.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   733
   * @param bool If true, enables all other parameters. Defaults to false, which emans that you can call this function with no arguments and it will fetch information from the config file.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   734
   * @param string Database server hostname
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   735
   * @param string Database server username
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   736
   * @param string Database server password
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   737
   * @param string Name of the database
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   738
   * @param int Optional port number to connect over
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   739
   */
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   740
  
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   741
  function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   742
  {
483
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   743
    if ( !defined('ENANO_SQL_CONSTANTS') )
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   744
    {
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   745
      define('ENANO_SQL_CONSTANTS', '');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   746
      define('ENANO_DBLAYER', 'PGSQL');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   747
      define('ENANO_SQLFUNC_LOWERCASE', 'lower');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   748
      define('ENANO_SQL_MULTISTRING_PRFIX', 'E');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   749
      define('ENANO_SQL_BOOLEAN_TRUE', '1');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   750
      define('ENANO_SQL_BOOLEAN_FALSE', '0');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   751
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   752
    
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   753
    if ( !$manual_credentials )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   754
    {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   755
      if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   756
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   757
        @include(ENANO_ROOT.'/config.new.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   758
      }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   759
      else
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   760
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   761
        @include(ENANO_ROOT.'/config.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   762
      }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   763
        
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   764
      if ( isset($crypto_key) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   765
        unset($crypto_key); // Get this sucker out of memory fast
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   766
      if ( empty($dbport) )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   767
        $dbport = 5432;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   768
      
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   769
      if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   770
      {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   771
        // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   772
        if ( !defined('scriptPath') )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   773
        {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   774
          if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   775
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   776
            $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   777
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   778
          if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   779
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   780
            // user requested http://foo/enano as opposed to http://foo/enano/index.php
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   781
            $_SERVER['REQUEST_URI'] .= '/index.php';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   782
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   783
          $sp = dirname($_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   784
          if($sp == '/' || $sp == '\\') $sp = '';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   785
          define('scriptPath', $sp);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   786
          define('contentPath', "$sp/index.php?title=");
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   787
        }
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   788
        $loc = scriptPath . '/install.php';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   789
        // header("Location: $loc");
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   790
        redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   791
        exit;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   792
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   793
    }
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   794
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   795
    if ( empty($dbport) )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   796
      $dbport = 5432;
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   797
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   798
    $this->_conn = @pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpasswd");
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   799
    unset($dbuser);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   800
    unset($dbpasswd); // Security
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   801
    
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   802
    if ( !$this->_conn && !$manual_credentials )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   803
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   804
      grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to PostgreSQL.<br />'.pg_last_error().'</p>');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   805
    }
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   806
    else if ( !$this->_conn && $manual_credentials )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   807
    {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   808
      return false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   809
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   810
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   811
    // Reset some variables
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   812
    $this->query_backtrace = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   813
    $this->query_times = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   814
    $this->query_sources = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   815
    $this->num_queries = 0;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   816
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   817
    $this->debug = ( defined('ENANO_DEBUG') );
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   818
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   819
    // We're in!
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   820
    return true;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   821
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   822
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   823
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   824
   * Make a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   825
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   826
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   827
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   828
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   829
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   830
  function sql_query($q)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   831
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   832
    if ( $this->debug && function_exists('debug_backtrace') )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   833
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   834
      $backtrace = @debug_backtrace();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   835
      if ( is_array($backtrace) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   836
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   837
        $bt = $backtrace[0];
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   838
        if ( isset($backtrace[1]['class']) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   839
        {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   840
          if ( $backtrace[1]['class'] == 'sessionManager' )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   841
          {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   842
            $bt = $backtrace[1];
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   843
          }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   844
        }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   845
        $this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   846
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   847
      unset($backtrace);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   848
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   849
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   850
    $this->num_queries++;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   851
    $this->query_backtrace[] = $q;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   852
    $this->latest_query = $q;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   853
    // First make sure we have a connection
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   854
    if ( !$this->_conn )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   855
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   856
      $this->_die('A database connection has not yet been established.');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   857
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   858
    // Does this query look malicious?
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   859
    if ( !$this->check_query($q) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   860
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   861
      $this->report_query($q);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   862
      grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p><p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   863
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   864
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   865
    $time_start = microtime_float();
902
e7c6f1aa7b6a Cleared up a few warnings that appeared under the Phalanger PHP interpreter.
Dan
parents: 879
diff changeset
   866
    $r = @pg_query($this->_conn, $q);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   867
    $this->query_times[$q] = microtime_float() - $time_start;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   868
    $this->latest_result = $r;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   869
    return $r;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   870
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   871
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   872
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   873
   * Make a SQL query, but do not have PHP buffer all the results. Useful for queries that are expected to return a huge number of results.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   874
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   875
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   876
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   877
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   878
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   879
  function sql_unbuffered_query($q)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   880
  {
616
e311f5e6f904 Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents: 592
diff changeset
   881
    return $this->sql_query($q);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   882
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   883
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   884
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   885
   * Checks a SQL query for possible signs of injection attempts
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   886
   * @param string $q the query to check
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   887
   * @return bool true if query passed check, otherwise false
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   888
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   889
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   890
  function check_query($q, $debug = false)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   891
  {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   892
    global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   893
    $ts = microtime_float();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   894
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   895
    // remove properly escaped quotes
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   896
    $q = str_replace(array("\\\"", "\\'"), '', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   897
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   898
    // make sure quotes match
616
e311f5e6f904 Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents: 592
diff changeset
   899
    foreach ( array("'", '"') as $quote )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   900
    {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   901
      if ( get_char_count($q, $quote) % 2 == 1 )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   902
      {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   903
        // mismatched quotes
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   904
        return false;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   905
      }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   906
      // this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   907
      $q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   908
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   909
    $q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   910
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   911
    // quotes are now matched out. does this string have a comment marker in it?
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   912
    if ( strstr($q, '--') )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   913
    {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   914
      return false;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   915
    }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   916
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   917
    if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   918
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   919
      if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   920
      return false;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   921
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   922
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   923
    $ts = microtime_float() - $ts;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   924
    $db_sql_parse_time += $ts;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   925
    return true;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   926
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   927
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   928
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   929
   * Set the internal result pointer to X
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   930
   * @param int $pos The number of the row
879
9788f2b7e08a Corrected a few display issues in Postgres DBAL. Thanks Neal.
Dan
parents: 860
diff changeset
   931
   * @param resource $result The PostgreSQL result resource - if not given, the latest cached query is assumed
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   932
   * @return true on success, false on failure
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   933
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   934
   
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   935
  function sql_data_seek($pos, $result = false)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   936
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   937
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   938
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   939
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   940
      return false;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   941
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   942
    return pg_result_seek($result, $pos) ? true : false;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   943
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   944
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   945
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   946
   * Reports a bad query to the admin
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   947
   * @param string $query the naughty query
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   948
   * @access private
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   949
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   950
   
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   951
  function report_query($query)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   952
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   953
    global $session;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   954
    if(is_object($session) && defined('ENANO_MAINSTREAM'))
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   955
      $username = $session->username;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   956
    else
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   957
      $username = 'Unavailable';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   958
    $query = $this->escape($query);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   959
    $q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            edit_summary)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   960
                                                     VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', \''.$_SERVER['REMOTE_ADDR'].'\');');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   961
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   962
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   963
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   964
   * Returns the ID of the row last inserted.
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   965
   * @return int
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   966
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   967
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   968
  function insert_id()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   969
  {
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   970
    // list of primary keys in Enano tables
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   971
    // this is a bit hackish, but not much choice.
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   972
    static $primary_keys = false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   973
    if ( !is_array($primary_keys) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   974
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   975
      $primary_keys = array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   976
        table_prefix . 'comments' => 'comment_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   977
        table_prefix . 'logs' => 'log_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   978
        table_prefix . 'users' => 'user_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   979
        table_prefix . 'banlist' => 'ban_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   980
        table_prefix . 'files' => 'file_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   981
        table_prefix . 'buddies' => 'buddy_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   982
        table_prefix . 'privmsgs' => 'message_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   983
        table_prefix . 'sidebar' => 'item_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   984
        table_prefix . 'hits' => 'hit_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   985
        table_prefix . 'groups' => 'group_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   986
        table_prefix . 'group_members' => 'member_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   987
        table_prefix . 'acl' => 'rule_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   988
        table_prefix . 'page_groups' => 'pg_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   989
        table_prefix . 'page_group_members' => 'pg_member_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   990
        table_prefix . 'tags' => 'tag_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   991
        table_prefix . 'lockout' => 'id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   992
        table_prefix . 'language' => 'lang_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   993
        table_prefix . 'language_strings' => 'string_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   994
        table_prefix . 'ranks' => 'rank_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   995
        table_prefix . 'captcha' => 'code_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   996
        table_prefix . 'diffiehellman' => 'key_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   997
        table_prefix . 'plugins' => 'plugin_id'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   998
      );
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   999
      // allow plugins to patch this if needed
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1000
      global $plugins;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1001
      $code = $plugins->setHook('pgsql_set_serial_list');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1002
      foreach ( $code as $cmd )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1003
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1004
        eval($cmd);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1005
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1006
    }
636
c9ea830a211f Fixed a few more PostgreSQL bugs with insert_id() and an issue with setting SERIAL columns manually. May break things if installed into a database without first dropping tables.
Dan
parents: 628
diff changeset
  1007
    $last_was_insert = preg_match('/^INSERT INTO ([a-z0-9_]+)/i', $this->latest_query, $match);
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1008
    if ( $last_was_insert )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1009
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1010
      // trick based on PunBB's PostgreSQL driver
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1011
      $table =& $match[1];
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1012
      if ( isset($primary_keys[$table]) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1013
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1014
        $primary_key = "{$table}_{$primary_keys[$table]}_seq";
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1015
        $q = pg_query("SELECT CURRVAL('$primary_key');");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1016
        return ( $q ) ? intval(@pg_fetch_result($q, 0)) : false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1017
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1018
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1019
    return false;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1020
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1021
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1022
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1023
   * Fetch one row from the given query as an associative array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1024
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1025
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1026
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1027
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1028
  function fetchrow($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1029
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1030
    if ( !$this->_conn )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1031
      return false;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1032
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1033
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1034
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1035
      $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1036
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1037
    $row = pg_fetch_assoc($r);
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
  1038
    return integerize_array($row);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1039
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1040
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1041
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1042
   * Fetch one row from the given query as a numeric array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1043
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1044
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1045
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1046
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1047
  function fetchrow_num($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1048
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1049
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1050
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1051
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1052
      $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1053
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1054
    $row = pg_fetch_row($r);
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
  1055
    return integerize_array($row);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1056
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1057
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1058
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1059
   * Get the number of results for a given query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1060
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1061
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1062
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1063
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1064
  function numrows($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1065
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1066
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1067
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1068
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1069
      $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1070
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1071
    $n = pg_num_rows($r);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1072
    return $n;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1073
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1074
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1075
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1076
   * Escape a string so that it may safely be included in a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1077
   * @param string String to escape
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1078
   * @return string Escaped string
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1079
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1080
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1081
  function escape($str)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1082
  {
860
c931041e689a DBAL: Fixed missing $loc in pgsql die_json()
Dan
parents: 857
diff changeset
  1083
    $str = pg_escape_string($this->_conn, $str);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1084
    return $str;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1085
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1086
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1087
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1088
   * Free the given result from memory. Use this when completely finished with a result resource.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1089
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1090
   * @return null
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1091
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1092
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1093
  function free_result($result = false)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1094
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1095
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1096
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1097
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1098
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1099
      return null;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1100
    
374
5c740e430a05 [minor] silenced errors to mysql_free_result() and pg_free_result()
Dan
parents: 352
diff changeset
  1101
    @pg_free_result($result);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1102
    return null;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1103
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1104
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1105
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1106
   * Close the database connection
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1107
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1108
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1109
  function close()
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1110
  {
503
f205f4b201ed [minor] silence errors when closing DB connections
Dan
parents: 483
diff changeset
  1111
    @pg_close($this->_conn);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1112
    unset($this->_conn);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1113
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1114
  
1147
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1115
  /**
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1116
   * Get a list of columns in the given table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1117
   * @param string Table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1118
   * @return array
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1119
   */
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1120
  
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1121
  function columns_in($table)
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1122
  {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1123
    if ( !is_string($table) )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1124
      return false;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1125
    $q = $this->sql_query("SELECT * FROM $table LIMIT 1 OFFSET 0;");
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1126
    if ( !$q )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1127
      $this->_die();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1128
    if ( $this->numrows() < 1 )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1129
    {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1130
      // FIXME: Have another way to do this if the table is empty
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1131
      return false;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1132
    }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1133
    
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1134
    $row = $this->fetchrow();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1135
    $this->free_result();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1136
    return array_keys($row);
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1137
  }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1138
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1139
	function sql_error()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1140
	{
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1141
		if ( $this->_conn )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1142
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1143
			return pg_last_error();
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1144
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1145
		else
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1146
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1147
			return ( defined('IN_ENANO_INSTALL') ) ? $GLOBALS["lang"]->get('dbpgsql_msg_err_auth') : 'Access to the database was denied. Ensure that your database exists and that your username and password are correct.';
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1148
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1149
	}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1150
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1151
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1152
   * Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1153
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1154
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1155
  function sql_report()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1156
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1157
    global $db, $session, $paths, $template, $plugins; // Common objects
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1158
    if ( !$session->get_permissions('mod_misc') )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1159
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1160
      die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1161
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1162
    // Create copies of variables that may be changed after header is called
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1163
    $backtrace = $this->query_backtrace;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1164
    $times = $this->query_times;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1165
    $template->header();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1166
    echo '<h3>SQL query log and timetable</h3>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1167
    echo '<div class="tblholder">
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1168
            <table border="0" cellspacing="1" cellpadding="4">';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1169
    $i = 0;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1170
    foreach ( $backtrace as $query )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1171
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1172
      $i++;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1173
      $unbuffered = false;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1174
      if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1175
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1176
        $query = substr($query, 13);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1177
        $unbuffered = true;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1178
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1179
      if ( $i == 1 )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1180
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1181
        echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1182
                <th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1183
              </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1184
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1185
      else
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1186
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1187
        echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1188
                <th class="subhead" colspan="2">&nbsp;</th>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1189
              </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1190
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1191
      echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1192
              <td class="row2">Query:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1193
              <td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1194
            </tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1195
            <tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1196
              <td class="row2">Time:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1197
              <td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1198
            </tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1199
            <tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1200
              <td class="row2">Unbuffered:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1201
              <td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1202
            </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1203
      if ( isset($this->query_sources[$query]) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1204
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1205
        echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1206
                <td class="row2">Called from:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1207
                <td class="row1">' . $this->query_sources[$query] . '</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1208
              </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1209
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1210
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1211
    if ( function_exists('array_sum') )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1212
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1213
      $query_time_total = array_sum($this->query_times);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1214
      echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1215
              <th class="subhead" colspan="2">
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1216
                Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1217
              </th>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1218
            </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1219
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1220
    echo '  </table>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1221
          </div>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1222
    $template->footer();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1223
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1224
}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1225
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1226
?>