includes/dbal.php
author Dan Fuhry <dan@enanocms.org>
Wed, 21 Aug 2013 22:13:58 -0400
changeset 1376 60b580d22c7b
parent 1375 d66e43ac35b6
child 1377 fa2b0825bbc5
permissions -rw-r--r--
Merged
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
{
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    16
	if ( !defined('ENANO_DEBUG') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    17
		return;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    18
	$e = error_reporting(0);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    19
	error_reporting($e);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    20
	if ( $e < $errno )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    21
		return;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    22
	$errtype = 'Notice';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    23
	switch ( $errno )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    24
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    25
		case E_ERROR: case E_USER_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: $errtype = 'Error'; break;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    26
		case E_WARNING: case E_USER_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: $errtype = 'Warning'; break;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    27
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    28
	$debug = debug_backtrace();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    29
	if ( !isset($debug[0]['file']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    30
		return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    31
	$debug = $debug[0]['file'] . ', line ' . $debug[0]['line'];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    32
	echo "<b>$errtype:</b> $errstr<br />Error source:<pre>$debug</pre>";
1
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 {
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    39
	var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    40
	var $row = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    41
	var $rowset = array();
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    42
	var $errhandler;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    43
	var $dbms_name = 'MySQL';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    44
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    45
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    46
 	* Get a flat textual list of queries that have been made.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    47
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    48
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    49
	function sql_backtrace()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    50
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    51
		return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    52
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    53
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    54
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    55
 	* Connect to the database, but only if a connection isn't already up.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    56
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    57
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    58
	function ensure_connection()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    59
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    60
		if(!$this->_conn)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    61
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    62
			$this->connect();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    63
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    64
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    65
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    66
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    67
 	* Exit Enano, dumping out a friendly error message indicating a database error on the way out.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    68
 	* @param string Description or location of error; defaults to none
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    69
 	*/
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    70
 
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    71
	function _die($t = '')
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    72
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    73
		if ( defined('ENANO_HEADERS_SENT') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    74
			ob_clean();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    75
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    76
		$internal_text = $this->get_error($t);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    77
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    78
		if ( defined('ENANO_CONFIG_FETCHED') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    79
			// config is in, we can show a slightly nicer looking error page
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    80
			die_semicritical('Database error', $internal_text);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    81
		else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    82
			// no config, display using no-DB template engine
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    83
			grinding_halt('Database error', $internal_text);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    84
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    85
		exit;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    86
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    87
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    88
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    89
 	* Get the internal text used for a database error message.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    90
 	* @param string Description or location of error; defaults to none
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    91
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    92
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    93
	function get_error($t = '')
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    94
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    95
		@header('HTTP/1.1 500 Internal Server Error');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    96
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    97
		$bt = $this->latest_query;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    98
		$e = htmlspecialchars($this->sql_error());
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
    99
		if ( empty($e) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   100
			$e = '&lt;none&gt;';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   101
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   102
		global $email;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   103
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   104
		// As long as the admin's e-mail is accessible, display it.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   105
		$email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   106
										? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   107
										: '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   108
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   109
		$internal_text = "<h3>The site was unable to finish serving your request.</h3>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
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>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   111
											<p>Description or location of error: $t<br />
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   112
											Error returned by $this->dbms_name extension: $e</p>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   113
											<p>Most recent SQL query:</p>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   114
											<pre>$bt</pre>";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   115
		return $internal_text;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   116
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   117
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   118
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   119
 	* Exit Enano and output a JSON format datbase error.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   120
 	* @param string Description or location of error; defaults to none
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   121
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   122
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   123
	function die_json($loc = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   124
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   125
		$e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   126
		$q = str_replace("\n", "\\n", addslashes($this->latest_query));
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   127
		$loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
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.";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   129
		$loc = str_replace("\n", "\\n", $loc);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
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\"}";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   131
		die($t);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   132
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   133
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   134
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   135
 	* Connect to the database.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   137
 	* @param string Database server hostname
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   138
 	* @param string Database server username
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   139
 	* @param string Database server password
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   140
 	* @param string Name of the database
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   141
 	* @param int Optional port number to connect over
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   142
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   143
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   144
	function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   145
	{
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   146
		if ( !function_exists('mysql_connect') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   147
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   148
			if ( class_exists('PDO') && extension_loaded("pdo_mysql") )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   149
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   150
				$pdo_string = '<p><strong>Never fear!</strong> Your server has PDO and the PDO MySQL driver installed. This means you can simply edit your config.php to use
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   151
									an alternate database driver, without losing any of your existing site data. Look for the line that says:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   152
								<pre>$dbdriver = \'mysql\';</pre>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   153
								<p>and change it to:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   154
								<pre>$dbdriver = \'mysql_pdo\';</pre>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   155
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   156
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   157
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   158
				$pdo_string = '<p>Enano can\'t load right now, but it will resume working once you install the PDO MySQL extension and then edit Enano\'s config.php file to
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   159
									use the new database driver. Once the PDO and PDO_MySQL PHP extensions are installed, look in Enano\'s config.php file for
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   160
									the line that says:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   161
								<pre>$dbdriver = \'mysql\';</pre>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   162
								<p>and change it to:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   163
								<pre>$dbdriver = \'mysql_pdo\';</pre>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   164
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   165
			grinding_halt('MySQL no longer supported', '<p>Your site configuration specifies that the MySQL database driver is to be used, however PHP has removed this
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   166
								driver from newer versions.</p>' . $pdo_string .
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   167
								'<p><strong>Your site\'s data is not at risk.</strong> This notice by itself simply means you upgraded to a newer version of PHP. Your site\'s
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   168
									data ordinarily will not have been touched and your site will function properly again as soon as you switch over to the PDO MySQL
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   169
									driver.</p>');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   170
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   171
		
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   172
		if ( !defined('ENANO_SQL_CONSTANTS') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   173
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   174
			define('ENANO_SQL_CONSTANTS', '');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   175
			define('ENANO_DBLAYER', 'MYSQL');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   176
			define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   177
			define('ENANO_SQL_MULTISTRING_PRFIX', '');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   178
			define('ENANO_SQL_BOOLEAN_TRUE', 'true');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   179
			define('ENANO_SQL_BOOLEAN_FALSE', 'false');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   180
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   181
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   182
		if ( !$manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   183
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   184
			if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   185
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   186
				@include(ENANO_ROOT.'/config.new.php');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   187
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   188
			else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   189
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   190
				@include(ENANO_ROOT.'/config.php');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   191
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   192
			
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   193
			if ( isset($crypto_key) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   194
				unset($crypto_key); // Get this sucker out of memory fast
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   195
			if ( empty($dbport) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   196
				$dbport = 3306;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   197
			
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   198
			if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   199
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   200
				// scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   201
				if ( !defined('scriptPath') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   202
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   203
					if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   204
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   205
						$_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   206
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   207
					if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   208
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   209
						// user requested http://foo/enano as opposed to http://foo/enano/index.php
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   210
						$_SERVER['REQUEST_URI'] .= '/index.php';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   211
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   212
					$sp = dirname($_SERVER['REQUEST_URI']);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   213
					if($sp == '/' || $sp == '\\') $sp = '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   214
					define('scriptPath', $sp);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   215
					define('contentPath', "$sp/index.php?title=");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   216
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   217
				$loc = scriptPath . '/install/index.php';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   218
				define('IN_ENANO_INSTALL', 1);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   219
				$GLOBALS['lang'] = new Language('eng');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   220
				global $lang;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   221
				$lang->load_file('./language/english/core.json');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   222
				$lang->load_file('./language/english/install.json');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   223
				// header("Location: $loc");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   224
				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);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   225
				exit;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   226
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   227
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   228
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   229
		if ( !$dbport )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   230
			$dbport = 3306;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   231
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   232
		if ( $dbhost && !empty($dbport) && $dbport != 3306 )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   233
			$dbhost = '127.0.0.1';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   234
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   235
		$host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   236
		
1369
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   237
		// Try a peristent connection twice
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   238
		// http://us2.php.net/manual/en/function.mysql-pconnect.php#99380
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   239
		$this->_conn = @mysql_pconnect($host_line, $dbuser, $dbpasswd);
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   240
		if ( !@mysql_query("SELECT 1;", $this->_conn) )
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   241
		{
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   242
			$this->_conn = @mysql_pconnect($host_line, $dbuser, $dbpasswd);
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   243
			if ( !@mysql_query("SELECT 1;", $this->_conn) )
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   244
			{
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   245
				// if that doesn't work, use a normal connection
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   246
				$this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd);
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   247
				trigger_error(E_USER_WARNING, "Forced to use nonpersistent mysql connection");
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   248
			}
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   249
		}
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   250
		unset($dbuser);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   251
		unset($dbpasswd); // Security
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   252
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   253
		if ( !$this->_conn && !$manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   254
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   255
			grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to MySQL.<br />'.mysql_error().'</p>');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   256
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   257
		else if ( !$this->_conn && $manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   258
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   259
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   260
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   261
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   262
		// Reset some variables
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   263
		$this->query_backtrace = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   264
		$this->query_times = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   265
		$this->query_sources = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   266
		$this->num_queries = 0;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   267
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   268
		$this->debug = ( defined('ENANO_DEBUG') );
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   269
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   270
		$q = @mysql_select_db($dbname);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   271
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   272
		if ( !$q )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   273
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   274
			if ( $manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   275
				return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   276
			$this->_die('The database could not be selected.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   277
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   278
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   279
		// We're in!
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   280
		return true;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   281
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   282
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   283
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   284
 	* Make a SQL query.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   285
 	* @param string Query
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   286
 	* @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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   287
 	* @return resource or false on failure
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   288
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   289
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   290
	function sql_query($q, $log_query = true)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   291
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   292
		if ( $this->debug && function_exists('debug_backtrace') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   293
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   294
			$backtrace = @debug_backtrace();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   295
			if ( is_array($backtrace) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   296
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   297
				$bt = $backtrace[0];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   298
				if ( isset($backtrace[1]['class']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   299
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   300
					if ( $backtrace[1]['class'] == 'sessionManager' )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   301
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   302
						$bt = $backtrace[1];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   303
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   304
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   305
				$this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   306
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   307
			unset($backtrace);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   308
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   309
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   310
		$this->num_queries++;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   311
		if ( $log_query || defined('ENANO_DEBUG') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   312
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   313
			$this->query_backtrace[] = $q;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   314
			$this->latest_query = $q;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   315
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   316
		// First make sure we have a connection
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   317
		if ( !$this->_conn )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   318
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   319
			$this->_die('A database connection has not yet been established.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   320
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   321
		// Start the timer
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   322
		if ( $log_query || defined('ENANO_DEBUG') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   323
			$time_start = microtime_float();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   324
		// Does this query look malicious?
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   325
		if ( $log_query || defined('ENANO_DEBUG') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   326
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   327
			if ( !$this->check_query($q) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   328
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   329
				$this->report_query($q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   330
				$debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   331
				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);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   332
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   333
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   334
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   335
		$r = mysql_query($q, $this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   336
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   337
		if ( $log_query )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   338
			$this->query_times[$q] = microtime_float() - $time_start;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   339
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   340
		$this->latest_result = $r;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   341
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   342
		return $r;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   343
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   344
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   345
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   346
 	* 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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   347
 	* @param string Query
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   348
 	* @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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   349
 	* @return resource or false on failure
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   350
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   351
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   352
	function sql_unbuffered_query($q, $log_query = true)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   353
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   354
		$this->num_queries++;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   355
		if ( $log_query || defined('ENANO_DEBUG') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   356
			$this->query_backtrace[] = '(UNBUFFERED) ' . $q;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   357
		$this->latest_query = $q;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   358
		// First make sure we have a connection
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   359
		if ( !$this->_conn )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   360
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   361
			$this->_die('A database connection has not yet been established.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   362
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   363
		// Does this query look malicious?
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   364
		if ( !$this->check_query($q) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   365
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   366
			$this->report_query($q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   367
			$debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   368
			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);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   369
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   370
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   371
		$time_start = microtime_float();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   372
		$r = @mysql_unbuffered_query($q, $this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   373
		$this->query_times[$q] = microtime_float() - $time_start;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   374
		$this->latest_result = $r;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   375
		return $r;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   376
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   377
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   378
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   379
 	* Performs heuristic analysis on a SQL query to check for known attack patterns.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   380
 	* @param string $q the query to check
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   381
 	* @return bool true if query passed check, otherwise false
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   382
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   383
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   384
	function check_query($q, $debug = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   385
	{
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   386
		global $db_sql_parse_time;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   387
		$ts = microtime_float();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   388
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   389
		// remove properly escaped quotes
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   390
		$q = str_replace('\\\\', '', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   391
		$q = str_replace(array("\\\"", "\\'"), '', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   392
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   393
		// make sure quotes match
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   394
		foreach ( array("'", '"') as $quote )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   395
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   396
			$n_quotes = get_char_count($q, $quote);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   397
			if ( $n_quotes % 2 == 1 )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   398
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   399
				// mismatched quotes
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   400
				if ( $debug ) echo "Found mismatched quotes in query; parsed:\n$q\n";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   401
				return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   402
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   403
			// this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   404
			$q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   405
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   406
		$q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   407
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   408
		// quotes are now matched out. does this string have a comment marker in it?
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   409
		if ( strstr($q, '--') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   410
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   411
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   412
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   413
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   414
		if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   415
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   416
			if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   417
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   418
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   419
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   420
		$ts = microtime_float() - $ts;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   421
		$db_sql_parse_time += $ts;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   422
		return true;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   423
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   424
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   425
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   426
 	* Set the internal result pointer to X
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   427
 	* @param int $pos The number of the row
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   428
 	* @param resource $result The MySQL result resource - if not given, the latest cached query is assumed
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   429
 	* @return true on success, false on failure
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   430
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   431
 	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   432
	function sql_data_seek($pos, $result = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   433
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   434
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   435
			$result = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   436
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   437
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   438
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   439
		return mysql_data_seek($result, $pos) ? true : false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   440
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   441
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   442
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   443
 	* Reports a bad query to the admin
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   444
 	* @param string $query the naughty query
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   445
 	* @access private
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   446
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   447
 	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   448
	function report_query($query)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   449
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   450
		global $session;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   451
		if ( is_object($session) && defined('ENANO_MAINSTREAM') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   452
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   453
			$username = $session->username;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   454
			$user_id = $session->user_id;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   455
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   456
		else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   457
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   458
			$username = 'Unavailable';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   459
			$user_id = 1;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   460
		} 
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   461
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   462
		$query = $this->escape($query);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   463
		$q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            author_uid,       edit_summary)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   464
 																										VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', ' . $user_id . ', \''.$_SERVER['REMOTE_ADDR'].'\');');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   465
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   466
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   467
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   468
 	* Returns the ID of the row last inserted.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   469
 	* @return int
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   470
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   471
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   472
	function insert_id()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   473
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   474
		return @mysql_insert_id();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   475
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   476
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   477
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   478
 	* Fetch one row from the given query as an associative array.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   479
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   480
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   481
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   482
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   483
	function fetchrow($r = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   484
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   485
		if ( !$this->_conn )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   486
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   487
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   488
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   489
			$r = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   490
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   491
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   492
			$this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   493
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   494
		$row = mysql_fetch_assoc($r);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   495
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   496
		return integerize_array($row);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   497
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   498
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   499
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   500
 	* Fetch one row from the given query as a numeric array.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   501
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   502
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   503
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   504
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   505
	function fetchrow_num($r = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   506
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   507
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   508
			$r = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   509
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   510
			$this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   511
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   512
		$row = mysql_fetch_row($r);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   513
		return integerize_array($row);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   514
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   515
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   516
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   517
 	* Get the number of results for a given query.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   518
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   519
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   520
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   521
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   522
	function numrows($r = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   523
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   524
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   525
			$r = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   526
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   527
			$this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   528
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   529
		return mysql_num_rows($r);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   530
	}
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   531
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   532
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   533
 	* Escape a string so that it may safely be included in a SQL query.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   534
 	* @param string String to escape
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   535
 	* @return string Escaped string
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   536
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   537
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   538
	function escape($str)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   539
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   540
		$str = mysql_real_escape_string($str);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   541
		return $str;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   542
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   543
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   544
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   545
 	* Free the given result from memory. Use this when completely finished with a result resource.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   546
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   547
 	* @return null
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   548
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   549
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   550
	function free_result($result = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   551
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   552
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   553
			$result = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   554
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   555
			return null;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   556
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   557
		@mysql_free_result($result);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   558
		return null;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   559
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   560
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   561
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   562
 	* Returns the number of rows affected.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   563
 	* @return int
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   564
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   565
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   566
	function sql_affectedrows()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   567
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   568
		return mysql_affected_rows($this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   569
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   570
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   571
	/**
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   572
	* Get MySQL server version
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   573
	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   574
	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   575
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   576
	function get_server_version()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   577
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   578
		return mysql_get_server_info();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   579
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   580
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   581
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   582
 	* Close the database connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   583
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   584
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   585
	function close()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   586
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   587
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   588
			return;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   589
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   590
		// anything we locked should certainly be unlocked now;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   591
		@mysql_query("COMMIT;", $this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   592
		@mysql_query("UNLOCK TABLES;", $this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   593
		@mysql_close($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   594
		unset($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   595
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   596
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   597
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   598
 	* Get a list of columns in the given table
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   599
 	* @param string Table
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   600
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   601
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   602
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   603
	function columns_in($table)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   604
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   605
		if ( !is_string($table) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   606
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   607
		$q = $this->sql_query("SHOW COLUMNS IN $table;");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   608
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   609
			$this->_die();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   610
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   611
		$columns = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   612
		while ( $row = $this->fetchrow_num() )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   613
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   614
			$columns[] = $row[0];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   615
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   616
		return $columns;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   617
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   618
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   619
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   620
 	* Get the text of the most recent error.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   621
 	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   622
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   623
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   624
	function sql_error()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   625
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   626
		return mysql_error();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   627
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   628
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   629
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   630
 	* Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   631
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   632
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   633
	function sql_report()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   634
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   635
		global $db, $session, $paths, $template, $plugins; // Common objects
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   636
		if ( !$session->get_permissions('mod_misc') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   637
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   638
			die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   639
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   640
		// Create copies of variables that may be changed after header is called
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   641
		$backtrace = $this->query_backtrace;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   642
		$times = $this->query_times;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   643
		$template->header();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   644
		echo '<h3>SQL query log and timetable</h3>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   645
		echo '<div class="tblholder">
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   646
						<table border="0" cellspacing="1" cellpadding="4">';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   647
		$i = 0;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   648
		foreach ( $backtrace as $query )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   649
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   650
			$i++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   651
			$unbuffered = false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   652
			if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   653
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   654
				$query = substr($query, 13);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   655
				$unbuffered = true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   656
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   657
			if ( $i == 1 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   658
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   659
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   660
								<th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   661
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   662
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   663
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   664
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   665
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   666
								<th class="subhead" colspan="2">&nbsp;</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   667
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   668
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   669
			echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   670
							<td class="row2">Query:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   671
							<td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   672
						</tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   673
						<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   674
							<td class="row2">Time:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   675
							<td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   676
						</tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   677
						<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   678
							<td class="row2">Unbuffered:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   679
							<td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   680
						</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   681
			if ( isset($this->query_sources[$query]) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   682
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   683
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   684
								<td class="row2">Called from:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   685
								<td class="row1">' . $this->query_sources[$query] . '</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   686
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   687
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   688
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   689
		if ( function_exists('array_sum') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   690
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   691
			$query_time_total = array_sum($this->query_times);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   692
			echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   693
							<th class="subhead" colspan="2">
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   694
								Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   695
							</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   696
						</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   697
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   698
		echo '  </table>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   699
					</div>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   700
		$template->footer();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   701
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   702
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   703
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   704
	 * Begin transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   705
	 */
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   706
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   707
	function transaction_begin()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   708
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   709
		$this->sql_query('BEGIN;');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   710
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   711
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   712
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   713
	 * Commit transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   714
	 */
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   715
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   716
	function transaction_commit()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   717
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   718
		$this->sql_query('COMMIT;');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   719
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   720
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   721
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   722
	 * Rollback transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   723
	 */
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   724
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   725
	function transaction_rollback()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   726
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   727
		$this->sql_query('ROLLBACK;');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   728
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   729
}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   730
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   731
class mysql_pdo {
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   732
	var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   733
	var $row = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   734
	var $rowset = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   735
	var $errhandler;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   736
	var $dbms_name = 'MySQL';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   737
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   738
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   739
 	* Get a flat textual list of queries that have been made.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   740
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   741
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   742
	function sql_backtrace()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   743
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   744
		return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   745
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   746
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   747
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   748
 	* Connect to the database, but only if a connection isn't already up.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   749
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   750
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   751
	function ensure_connection()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   752
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   753
		if(!$this->_conn)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   754
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   755
			$this->connect();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   756
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   757
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   758
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   759
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   760
 	* Exit Enano, dumping out a friendly error message indicating a database error on the way out.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   761
 	* @param string Description or location of error; defaults to none
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   762
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   763
 
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   764
	function _die($t = '')
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   765
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   766
		if ( defined('ENANO_HEADERS_SENT') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   767
			ob_clean();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   768
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   769
		$internal_text = $this->get_error($t);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   770
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   771
		if ( defined('ENANO_CONFIG_FETCHED') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   772
			// config is in, we can show a slightly nicer looking error page
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   773
			die_semicritical('Database error', $internal_text);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   774
		else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   775
			// no config, display using no-DB template engine
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   776
			grinding_halt('Database error', $internal_text);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   777
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   778
		exit;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   779
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   780
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   781
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   782
 	* Get the internal text used for a database error message.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   783
 	* @param string Description or location of error; defaults to none
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   784
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   785
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   786
	function get_error($t = '')
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   787
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   788
		@header('HTTP/1.1 500 Internal Server Error');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   789
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   790
		$bt = $this->latest_query;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   791
		$e = htmlspecialchars($this->sql_error());
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   792
		if ( empty($e) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   793
			$e = '&lt;none&gt;';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   794
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   795
		global $email;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   796
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   797
		// As long as the admin's e-mail is accessible, display it.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   798
		$email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   799
										? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   800
										: '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   801
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   802
		$internal_text = "<h3>The site was unable to finish serving your request.</h3>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   803
											<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>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   804
											<p>Description or location of error: $t<br />
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   805
											Error returned by $this->dbms_name extension: $e</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   806
											<p>Most recent SQL query:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   807
											<pre>$bt</pre>";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   808
		return $internal_text;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   809
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   810
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   811
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   812
 	* Exit Enano and output a JSON format datbase error.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   813
 	* @param string Description or location of error; defaults to none
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   814
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   815
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   816
	function die_json($loc = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   817
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   818
		$e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   819
		$q = str_replace("\n", "\\n", addslashes($this->latest_query));
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   820
		$loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   821
		$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.";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   822
		$loc = str_replace("\n", "\\n", $loc);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   823
		$t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   824
		die($t);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   825
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   826
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   827
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   828
 	* Connect to the database.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   829
 	* @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.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   830
 	* @param string Database server hostname
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   831
 	* @param string Database server username
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   832
 	* @param string Database server password
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   833
 	* @param string Name of the database
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   834
 	* @param int Optional port number to connect over
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   835
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   836
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   837
	function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   838
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   839
		if ( !defined('ENANO_SQL_CONSTANTS') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   840
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   841
			define('ENANO_SQL_CONSTANTS', '');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   842
			define('ENANO_DBLAYER', 'MYSQL');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   843
			define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   844
			define('ENANO_SQL_MULTISTRING_PRFIX', '');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   845
			define('ENANO_SQL_BOOLEAN_TRUE', 'true');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   846
			define('ENANO_SQL_BOOLEAN_FALSE', 'false');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   847
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   848
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   849
		if ( !$manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   850
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   851
			if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   852
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   853
				@include(ENANO_ROOT.'/config.new.php');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   854
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   855
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   856
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   857
				@include(ENANO_ROOT.'/config.php');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   858
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   859
			
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   860
			if ( isset($crypto_key) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   861
				unset($crypto_key); // Get this sucker out of memory fast
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   862
			if ( empty($dbport) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   863
				$dbport = 3306;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   864
			
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   865
			if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   866
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   867
				// scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   868
				if ( !defined('scriptPath') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   869
				{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   870
					if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   871
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   872
						$_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   873
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   874
					if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   875
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   876
						// user requested http://foo/enano as opposed to http://foo/enano/index.php
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   877
						$_SERVER['REQUEST_URI'] .= '/index.php';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   878
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   879
					$sp = dirname($_SERVER['REQUEST_URI']);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   880
					if($sp == '/' || $sp == '\\') $sp = '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   881
					define('scriptPath', $sp);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   882
					define('contentPath', "$sp/index.php?title=");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   883
				}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   884
				$loc = scriptPath . '/install/index.php';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   885
				define('IN_ENANO_INSTALL', 1);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   886
				$GLOBALS['lang'] = new Language('eng');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   887
				global $lang;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   888
				$lang->load_file('./language/english/core.json');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   889
				$lang->load_file('./language/english/install.json');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   890
				// header("Location: $loc");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   891
				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);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   892
				exit;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   893
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   894
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   895
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   896
		if ( !$dbport )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   897
			$dbport = 3306;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   898
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   899
		if ( $dbhost && !empty($dbport) && $dbport != 3306 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   900
			$dbhost = '127.0.0.1';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   901
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   902
		$host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   903
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   904
		$this->_conn = new PDO("mysql:host=$dbhost;dbname=$dbname;charset=UTF8", $dbuser, $dbpasswd);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   905
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   906
		unset($dbuser);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   907
		unset($dbpasswd); // Security
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   908
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   909
		if ( !$this->_conn && !$manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   910
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   911
			grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to MySQL.<br />'.mysql_error().'</p>');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   912
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   913
		else if ( !$this->_conn && $manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   914
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   915
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   916
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   917
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   918
		// Reset some variables
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   919
		$this->query_backtrace = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   920
		$this->query_times = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   921
		$this->query_sources = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   922
		$this->num_queries = 0;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   923
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   924
		$this->debug = ( defined('ENANO_DEBUG') );
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   925
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   926
		// We're in!
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   927
		return true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   928
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   929
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   930
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   931
 	* Make a SQL query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   932
 	* @param string Query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   933
 	* @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.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   934
 	* @return resource or false on failure
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   935
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   936
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   937
	function sql_query($q, $log_query = true)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   938
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   939
		if ( $this->debug && function_exists('debug_backtrace') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   940
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   941
			$backtrace = @debug_backtrace();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   942
			if ( is_array($backtrace) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   943
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   944
				$bt = $backtrace[0];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   945
				if ( isset($backtrace[1]['class']) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   946
				{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   947
					if ( $backtrace[1]['class'] == 'sessionManager' )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   948
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   949
						$bt = $backtrace[1];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   950
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   951
				}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   952
				$this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   953
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   954
			unset($backtrace);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   955
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   956
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   957
		$this->num_queries++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   958
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   959
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   960
			$this->query_backtrace[] = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   961
			$this->latest_query = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   962
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   963
		// First make sure we have a connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   964
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   965
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   966
			$this->_die('A database connection has not yet been established.');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   967
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   968
		// Start the timer
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   969
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   970
			$time_start = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   971
		// Does this query look malicious?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   972
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   973
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   974
			if ( !$this->check_query($q) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   975
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   976
				$this->report_query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   977
				$debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   978
				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);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   979
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   980
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   981
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   982
		try
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   983
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   984
			$r = $this->_conn->query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   985
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   986
		catch ( PDOException $e )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   987
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   988
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   989
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   990
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   991
		if ( $log_query )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   992
			$this->query_times[$q] = microtime_float() - $time_start;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   993
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   994
		$this->latest_result = $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   995
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   996
		return $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   997
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   998
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   999
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1000
 	* 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.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1001
 	* @param string Query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1002
 	* @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.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1003
 	* @return resource or false on failure
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1004
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1005
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1006
	function sql_unbuffered_query($q, $log_query = true)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1007
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1008
		$this->num_queries++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1009
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1010
			$this->query_backtrace[] = '(UNBUFFERED) ' . $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1011
		$this->latest_query = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1012
		// First make sure we have a connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1013
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1014
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1015
			$this->_die('A database connection has not yet been established.');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1016
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1017
		// Does this query look malicious?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1018
		if ( !$this->check_query($q) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1019
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1020
			$this->report_query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1021
			$debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1022
			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);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1023
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1024
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1025
		$time_start = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1026
		try
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1027
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1028
			$r = $this->_conn->query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1029
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1030
		catch ( PDOException $e )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1031
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1032
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1033
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1034
		$this->query_times[$q] = microtime_float() - $time_start;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1035
		$this->latest_result = $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1036
		return $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1037
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1038
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1039
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1040
 	* Performs heuristic analysis on a SQL query to check for known attack patterns.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1041
 	* @param string $q the query to check
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1042
 	* @return bool true if query passed check, otherwise false
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1043
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1044
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1045
	function check_query($q, $debug = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1046
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1047
		global $db_sql_parse_time;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1048
		$ts = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1049
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1050
		// remove properly escaped quotes
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1051
		$q = str_replace('\\\\', '', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1052
		$q = str_replace(array("\\\"", "\\'"), '', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1053
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1054
		// make sure quotes match
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1055
		foreach ( array("'", '"') as $quote )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1056
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1057
			$n_quotes = get_char_count($q, $quote);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1058
			if ( $n_quotes % 2 == 1 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1059
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1060
				// mismatched quotes
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1061
				if ( $debug ) echo "Found mismatched quotes in query; parsed:\n$q\n";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1062
				return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1063
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1064
			// this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1065
			$q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1066
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1067
		$q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1068
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1069
		// quotes are now matched out. does this string have a comment marker in it?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1070
		if ( strstr($q, '--') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1071
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1072
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1073
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1074
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1075
		if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1076
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1077
			if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1078
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1079
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1080
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1081
		$ts = microtime_float() - $ts;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1082
		$db_sql_parse_time += $ts;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1083
		return true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1084
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1085
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1086
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1087
 	* Set the internal result pointer to X
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1088
 	* @param int $pos The number of the row
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1089
 	* @param resource $result The MySQL result resource - if not given, the latest cached query is assumed
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1090
 	* @return true on success, false on failure
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1091
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1092
 	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1093
	function sql_data_seek($pos, $result = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1094
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1095
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1096
			$result = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1097
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1098
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1099
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1100
		return mysql_data_seek($result, $pos) ? true : false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1101
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1102
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1103
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1104
 	* Reports a bad query to the admin
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1105
 	* @param string $query the naughty query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1106
 	* @access private
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1107
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1108
 	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1109
	function report_query($query)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1110
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1111
		global $session;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1112
		if ( is_object($session) && defined('ENANO_MAINSTREAM') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1113
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1114
			$username = $session->username;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1115
			$user_id = $session->user_id;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1116
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1117
		else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1118
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1119
			$username = 'Unavailable';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1120
			$user_id = 1;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1121
		} 
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1122
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1123
		$query = $this->escape($query);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1124
		$q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            author_uid,       edit_summary)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1125
 																										VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', ' . $user_id . ', \''.$_SERVER['REMOTE_ADDR'].'\');');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1126
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1127
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1128
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1129
 	* Returns the ID of the row last inserted.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1130
 	* @return int
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1131
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1132
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1133
	function insert_id()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1134
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1135
		$q = $this->sql_query("SELECT LAST_INSERT_ID();");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1136
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1137
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1138
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1139
		list($iid) = $this->fetchrow_num();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1140
		return $iid;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1141
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1142
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1143
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1144
 	* Fetch one row from the given query as an associative array.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1145
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1146
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1147
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1148
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1149
	function fetchrow($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1150
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1151
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1152
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1153
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1154
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1155
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1156
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1157
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1158
			$this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1159
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1160
		$row = $r->fetch(PDO::FETCH_ASSOC);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1161
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1162
		return integerize_array($row);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1163
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1164
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1165
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1166
 	* Fetch one row from the given query as a numeric array.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1167
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1168
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1169
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1170
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1171
	function fetchrow_num($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1172
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1173
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1174
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1175
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1176
			$this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1177
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1178
		$row = $r->fetch(PDO::FETCH_NUM);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1179
		return integerize_array($row);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1180
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1181
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1182
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1183
 	* Get the number of results for a given query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1184
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1185
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1186
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1187
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1188
	function numrows($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1189
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1190
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1191
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1192
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1193
			$this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1194
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1195
		return $r->rowCount();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1196
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1197
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1198
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1199
 	* Escape a string so that it may safely be included in a SQL query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1200
 	* @param string String to escape
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1201
 	* @return string Escaped string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1202
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1203
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1204
	function escape($str)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1205
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1206
		$str = substr($this->_conn->quote($str), 1, -1);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1207
		return $str;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1208
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1209
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1210
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1211
 	* Free the given result from memory. Use this when completely finished with a result resource.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1212
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1213
 	* @return null
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1214
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1215
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1216
	function free_result($result = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1217
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1218
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1219
			$result = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1220
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1221
			return null;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1222
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1223
		//@mysql_free_result($result);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1224
		return null;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1225
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1226
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1227
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1228
 	* Returns the number of rows affected.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1229
 	* @return int
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1230
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1231
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1232
	function sql_affectedrows()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1233
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1234
		return mysql_affected_rows($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1235
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1236
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1237
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1238
	* Get MySQL server version
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1239
	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1240
	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1241
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1242
	function get_server_version()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1243
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1244
		$q = $this->sql_query("SHOW VARIABLES WHERE Variable_name = 'version';");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1245
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1246
			$this->_die("while fetching MySQL server version");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1247
		$row = $this->fetchrow($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1248
		return $row['Value'];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1249
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1250
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1251
	/**
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1252
 	* Close the database connection
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1253
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1254
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1255
	function close()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1256
	{
1369
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
  1257
		// anything we locked should certainly be unlocked now;
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
  1258
		@mysql_query("COMMIT;", $this->_conn);
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
  1259
		@mysql_query("UNLOCK TABLES;", $this->_conn);
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1260
		@mysql_close($this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1261
		unset($this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1262
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1263
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1264
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1265
 	* Get a list of columns in the given table
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1266
 	* @param string Table
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1267
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1268
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1269
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1270
	function columns_in($table)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1271
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1272
		if ( !is_string($table) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1273
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1274
		$q = $this->sql_query("SHOW COLUMNS IN $table;");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1275
		if ( !$q )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1276
			$this->_die();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1277
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1278
		$columns = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1279
		while ( $row = $this->fetchrow_num() )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1280
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1281
			$columns[] = $row[0];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1282
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1283
		return $columns;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1284
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1285
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1286
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1287
 	* Get the text of the most recent error.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1288
 	* @return string
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1289
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1290
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1291
	function sql_error()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1292
	{
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1293
		list(,,$errtext) = $this->_conn->errorInfo();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1294
		return $errtext;
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1295
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1296
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1297
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1298
 	* Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1299
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1300
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1301
	function sql_report()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1302
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1303
		global $db, $session, $paths, $template, $plugins; // Common objects
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1304
		if ( !$session->get_permissions('mod_misc') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1305
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1306
			die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1307
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1308
		// Create copies of variables that may be changed after header is called
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1309
		$backtrace = $this->query_backtrace;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1310
		$times = $this->query_times;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1311
		$template->header();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1312
		echo '<h3>SQL query log and timetable</h3>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1313
		echo '<div class="tblholder">
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1314
						<table border="0" cellspacing="1" cellpadding="4">';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1315
		$i = 0;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1316
		foreach ( $backtrace as $query )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1317
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1318
			$i++;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1319
			$unbuffered = false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1320
			if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1321
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1322
				$query = substr($query, 13);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1323
				$unbuffered = true;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1324
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1325
			if ( $i == 1 )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1326
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1327
				echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1328
								<th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1329
							</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1330
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1331
			else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1332
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1333
				echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1334
								<th class="subhead" colspan="2">&nbsp;</th>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1335
							</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1336
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1337
			echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1338
							<td class="row2">Query:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1339
							<td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1340
						</tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1341
						<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1342
							<td class="row2">Time:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1343
							<td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1344
						</tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1345
						<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1346
							<td class="row2">Unbuffered:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1347
							<td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1348
						</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1349
			if ( isset($this->query_sources[$query]) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1350
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1351
				echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1352
								<td class="row2">Called from:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1353
								<td class="row1">' . $this->query_sources[$query] . '</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1354
							</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1355
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1356
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1357
		if ( function_exists('array_sum') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1358
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1359
			$query_time_total = array_sum($this->query_times);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1360
			echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1361
							<th class="subhead" colspan="2">
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1362
								Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1363
							</th>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1364
						</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1365
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1366
		echo '  </table>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1367
					</div>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1368
		$template->footer();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1369
	}
1342
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1370
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1371
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1372
	 * Begin transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1373
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1374
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1375
	function transaction_begin()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1376
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1377
		$this->sql_query('BEGIN;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1378
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1379
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1380
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1381
	 * Commit transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1382
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1383
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1384
	function transaction_commit()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1385
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1386
		$this->sql_query('COMMIT;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1387
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1388
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1389
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1390
	 * Rollback transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1391
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1392
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1393
	function transaction_rollback()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1394
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1395
		$this->sql_query('ROLLBACK;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1396
	}
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1397
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1398
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1399
class postgresql
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1400
{
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1401
	var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1402
	var $row = array();
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
  1403
	var $rowset = array();
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1404
	var $errhandler;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1405
	var $dbms_name = 'PostgreSQL';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1406
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1407
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1408
 	* Get a flat textual list of queries that have been made.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1409
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1410
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1411
	function sql_backtrace()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1412
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1413
		return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1414
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1415
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1416
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1417
 	* Connect to the database, but only if a connection isn't already up.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1418
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1419
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1420
	function ensure_connection()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1421
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1422
		if(!$this->_conn)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1423
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1424
			$this->connect();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1425
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1426
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1427
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1428
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1429
 	* Exit Enano, dumping out a friendly error message indicating a database error on the way out.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1430
 	* @param string Description or location of error; defaults to none
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1431
 	*/
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1432
 
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1433
	function _die($t = '')
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1434
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1435
		if ( defined('ENANO_HEADERS_SENT') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1436
			ob_clean();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1437
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1438
		$internal_text = $this->get_error($t);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1439
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1440
		if ( defined('ENANO_CONFIG_FETCHED') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1441
			// config is in, we can show a slightly nicer looking error page
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1442
			die_semicritical('Database error', $internal_text);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1443
		else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1444
			// no config, display using no-DB template engine
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1445
			grinding_halt('Database error', $internal_text);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1446
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1447
		exit;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1448
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1449
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1450
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1451
 	* Get the internal text used for a database error message.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1452
 	* @param string Description or location of error; defaults to none
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1453
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1454
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1455
	function get_error($t = '')
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1456
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1457
		@header('HTTP/1.1 500 Internal Server Error');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1458
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1459
		$bt = $this->latest_query;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1460
		$e = htmlspecialchars($this->sql_error());
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1461
		if ( empty($e) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1462
			$e = '&lt;none&gt;';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1463
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1464
		global $email;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1465
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1466
		// As long as the admin's e-mail is accessible, display it.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1467
		$email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1468
										? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1469
										: '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1470
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1471
		$internal_text = "<h3>The site was unable to finish serving your request.</h3>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1472
											<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>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1473
											<p>Description or location of error: $t<br />
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1474
											Error returned by $this->dbms_name extension: $e</p>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1475
											<p>Most recent SQL query:</p>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1476
											<pre>$bt</pre>";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1477
		return $internal_text;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1478
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1479
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1480
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1481
 	* Exit Enano and output a JSON format datbase error.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1482
 	* @param string Description or location of error; defaults to none
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1483
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1484
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1485
	function die_json($loc = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1486
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1487
		$e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1488
		$q = str_replace("\n", "\\n", addslashes($this->latest_query));
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1489
		$loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1490
		$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.";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1491
		$loc = str_replace("\n", "\\n", $loc);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1492
		$t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1493
		die($t);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1494
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1495
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1496
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1497
 	* Connect to the database.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1498
 	* @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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1499
 	* @param string Database server hostname
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1500
 	* @param string Database server username
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1501
 	* @param string Database server password
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1502
 	* @param string Name of the database
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1503
 	* @param int Optional port number to connect over
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1504
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1505
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1506
	function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1507
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1508
		if ( !defined('ENANO_SQL_CONSTANTS') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1509
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1510
			define('ENANO_SQL_CONSTANTS', '');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1511
			define('ENANO_DBLAYER', 'PGSQL');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1512
			define('ENANO_SQLFUNC_LOWERCASE', 'lower');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1513
			define('ENANO_SQL_MULTISTRING_PRFIX', 'E');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1514
			define('ENANO_SQL_BOOLEAN_TRUE', '1');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1515
			define('ENANO_SQL_BOOLEAN_FALSE', '0');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1516
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1517
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1518
		if ( !$manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1519
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1520
			if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1521
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1522
				@include(ENANO_ROOT.'/config.new.php');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1523
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1524
			else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1525
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1526
				@include(ENANO_ROOT.'/config.php');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1527
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1528
				
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1529
			if ( isset($crypto_key) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1530
				unset($crypto_key); // Get this sucker out of memory fast
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1531
			if ( empty($dbport) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1532
				$dbport = 5432;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1533
			
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1534
			if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1535
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1536
				// scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1537
				if ( !defined('scriptPath') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1538
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1539
					if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1540
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1541
						$_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1542
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1543
					if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1544
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1545
						// user requested http://foo/enano as opposed to http://foo/enano/index.php
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1546
						$_SERVER['REQUEST_URI'] .= '/index.php';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1547
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1548
					$sp = dirname($_SERVER['REQUEST_URI']);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1549
					if($sp == '/' || $sp == '\\') $sp = '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1550
					define('scriptPath', $sp);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1551
					define('contentPath', "$sp/index.php?title=");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1552
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1553
				$loc = scriptPath . '/install.php';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1554
				// header("Location: $loc");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1555
				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);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1556
				exit;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1557
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1558
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1559
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1560
		if ( empty($dbport) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1561
			$dbport = 5432;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1562
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1563
		$this->_conn = @pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpasswd");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1564
		unset($dbuser);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1565
		unset($dbpasswd); // Security
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1566
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1567
		if ( !$this->_conn && !$manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1568
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1569
			grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to PostgreSQL.<br />'.pg_last_error().'</p>');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1570
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1571
		else if ( !$this->_conn && $manual_credentials )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1572
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1573
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1574
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1575
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1576
		// Reset some variables
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1577
		$this->query_backtrace = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1578
		$this->query_times = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1579
		$this->query_sources = array();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1580
		$this->num_queries = 0;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1581
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1582
		$this->debug = ( defined('ENANO_DEBUG') );
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1583
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1584
		// We're in!
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1585
		return true;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1586
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1587
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1588
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1589
 	* Make a SQL query.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1590
 	* @param string Query
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1591
 	* @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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1592
 	* @return resource or false on failure
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1593
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1594
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1595
	function sql_query($q)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1596
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1597
		if ( $this->debug && function_exists('debug_backtrace') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1598
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1599
			$backtrace = @debug_backtrace();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1600
			if ( is_array($backtrace) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1601
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1602
				$bt = $backtrace[0];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1603
				if ( isset($backtrace[1]['class']) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1604
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1605
					if ( $backtrace[1]['class'] == 'sessionManager' )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1606
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1607
						$bt = $backtrace[1];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1608
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1609
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1610
				$this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1611
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1612
			unset($backtrace);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1613
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1614
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1615
		$this->num_queries++;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1616
		$this->query_backtrace[] = $q;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1617
		$this->latest_query = $q;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1618
		// First make sure we have a connection
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1619
		if ( !$this->_conn )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1620
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1621
			$this->_die('A database connection has not yet been established.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1622
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1623
		// Does this query look malicious?
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1624
		if ( !$this->check_query($q) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1625
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1626
			$this->report_query($q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1627
			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>');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1628
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1629
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1630
		$time_start = microtime_float();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1631
		$r = @pg_query($this->_conn, $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1632
		$this->query_times[$q] = microtime_float() - $time_start;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1633
		$this->latest_result = $r;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1634
		return $r;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1635
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1636
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1637
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1638
 	* 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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1639
 	* @param string Query
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1640
 	* @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.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1641
 	* @return resource or false on failure
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1642
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1643
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1644
	function sql_unbuffered_query($q)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1645
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1646
		return $this->sql_query($q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1647
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1648
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1649
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1650
 	* Checks a SQL query for possible signs of injection attempts
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1651
 	* @param string $q the query to check
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1652
 	* @return bool true if query passed check, otherwise false
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1653
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1654
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1655
	function check_query($q, $debug = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1656
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1657
		global $db_sql_parse_time;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1658
		$ts = microtime_float();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1659
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1660
		// remove properly escaped quotes
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1661
		$q = str_replace(array("\\\"", "\\'"), '', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1662
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1663
		// make sure quotes match
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1664
		foreach ( array("'", '"') as $quote )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1665
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1666
			if ( get_char_count($q, $quote) % 2 == 1 )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1667
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1668
				// mismatched quotes
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1669
				return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1670
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1671
			// this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1672
			$q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1673
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1674
		$q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1675
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1676
		// quotes are now matched out. does this string have a comment marker in it?
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1677
		if ( strstr($q, '--') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1678
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1679
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1680
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1681
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1682
		if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1683
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1684
			if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1685
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1686
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1687
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1688
		$ts = microtime_float() - $ts;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1689
		$db_sql_parse_time += $ts;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1690
		return true;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1691
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1692
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1693
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1694
 	* Set the internal result pointer to X
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1695
 	* @param int $pos The number of the row
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1696
 	* @param resource $result The PostgreSQL result resource - if not given, the latest cached query is assumed
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1697
 	* @return true on success, false on failure
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1698
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1699
 	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1700
	function sql_data_seek($pos, $result = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1701
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1702
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1703
			$result = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1704
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1705
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1706
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1707
		return pg_result_seek($result, $pos) ? true : false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1708
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1709
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1710
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1711
 	* Reports a bad query to the admin
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1712
 	* @param string $query the naughty query
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1713
 	* @access private
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1714
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1715
 	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1716
	function report_query($query)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1717
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1718
		global $session;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1719
		if ( is_object($session) && defined('ENANO_MAINSTREAM') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1720
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1721
			$username = $session->username;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1722
			$user_id = $session->user_id;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1723
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1724
		else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1725
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1726
			$username = 'Unavailable';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1727
			$user_id = 1;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1728
		} 
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1729
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1730
		$query = $this->escape($query);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1731
		$q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            author_uid,       edit_summary)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1732
 																										VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', ' . $user_id . ', \''.$_SERVER['REMOTE_ADDR'].'\');');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1733
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1734
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1735
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1736
 	* Returns the ID of the row last inserted.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1737
 	* @return int
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1738
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1739
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1740
	function insert_id()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1741
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1742
		// list of primary keys in Enano tables
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1743
		// this is a bit hackish, but not much choice.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1744
		static $primary_keys = false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1745
		if ( !is_array($primary_keys) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1746
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1747
			$primary_keys = array(
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1748
				table_prefix . 'comments' => 'comment_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1749
				table_prefix . 'logs' => 'log_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1750
				table_prefix . 'users' => 'user_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1751
				table_prefix . 'banlist' => 'ban_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1752
				table_prefix . 'files' => 'file_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1753
				table_prefix . 'buddies' => 'buddy_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1754
				table_prefix . 'privmsgs' => 'message_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1755
				table_prefix . 'sidebar' => 'item_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1756
				table_prefix . 'hits' => 'hit_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1757
				table_prefix . 'groups' => 'group_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1758
				table_prefix . 'group_members' => 'member_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1759
				table_prefix . 'acl' => 'rule_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1760
				table_prefix . 'page_groups' => 'pg_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1761
				table_prefix . 'page_group_members' => 'pg_member_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1762
				table_prefix . 'tags' => 'tag_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1763
				table_prefix . 'lockout' => 'id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1764
				table_prefix . 'language' => 'lang_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1765
				table_prefix . 'language_strings' => 'string_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1766
				table_prefix . 'ranks' => 'rank_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1767
				table_prefix . 'captcha' => 'code_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1768
				table_prefix . 'diffiehellman' => 'key_id',
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1769
				table_prefix . 'plugins' => 'plugin_id'
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1770
			);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1771
			// allow plugins to patch this if needed
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1772
			global $plugins;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1773
			$code = $plugins->setHook('pgsql_set_serial_list');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1774
			foreach ( $code as $cmd )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1775
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1776
				eval($cmd);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1777
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1778
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1779
		$last_was_insert = preg_match('/^INSERT INTO ([a-z0-9_]+)/i', $this->latest_query, $match);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1780
		if ( $last_was_insert )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1781
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1782
			// trick based on PunBB's PostgreSQL driver
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1783
			$table =& $match[1];
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1784
			if ( isset($primary_keys[$table]) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1785
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1786
				$primary_key = "{$table}_{$primary_keys[$table]}_seq";
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1787
				$q = pg_query("SELECT CURRVAL('$primary_key');");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1788
				return ( $q ) ? intval(@pg_fetch_result($q, 0)) : false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1789
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1790
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1791
		return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1792
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1793
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1794
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1795
 	* Fetch one row from the given query as an associative array.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1796
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1797
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1798
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1799
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1800
	function fetchrow($r = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1801
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1802
		if ( !$this->_conn )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1803
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1804
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1805
			$r = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1806
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1807
			$this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1808
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1809
		$row = pg_fetch_assoc($r);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1810
		return integerize_array($row);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1811
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1812
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1813
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1814
 	* Fetch one row from the given query as a numeric array.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1815
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1816
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1817
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1818
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1819
	function fetchrow_num($r = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1820
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1821
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1822
			$r = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1823
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1824
			$this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1825
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1826
		$row = pg_fetch_row($r);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1827
		return integerize_array($row);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1828
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1829
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1830
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1831
 	* Get the number of results for a given query.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1832
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1833
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1834
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1835
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1836
	function numrows($r = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1837
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1838
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1839
			$r = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1840
		if ( !$r )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1841
			$this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1842
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1843
		$n = pg_num_rows($r);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1844
		return $n;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1845
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1846
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1847
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1848
 	* Escape a string so that it may safely be included in a SQL query.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1849
 	* @param string String to escape
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1850
 	* @return string Escaped string
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1851
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1852
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1853
	function escape($str)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1854
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1855
		$str = pg_escape_string($this->_conn, $str);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1856
		return $str;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1857
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1858
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1859
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1860
 	* Free the given result from memory. Use this when completely finished with a result resource.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1861
 	* @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1862
 	* @return null
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1863
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1864
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1865
	function free_result($result = false)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1866
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1867
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1868
			$result = $this->latest_result;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1869
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1870
		if ( !$result )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1871
			return null;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1872
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1873
		@pg_free_result($result);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1874
		return null;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1875
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1876
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1877
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1878
 	* Close the database connection
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1879
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1880
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1881
	function close()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1882
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1883
		@pg_close($this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1884
		unset($this->_conn);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1885
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1886
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1887
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1888
 	* Get a list of columns in the given table
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1889
 	* @param string Table
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1890
 	* @return array
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1891
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1892
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1893
	function columns_in($table)
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1894
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1895
		if ( !is_string($table) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1896
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1897
		$q = $this->sql_query("SELECT * FROM $table LIMIT 1 OFFSET 0;");
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1898
		if ( !$q )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1899
			$this->_die();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1900
		if ( $this->numrows() < 1 )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1901
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1902
			// FIXME: Have another way to do this if the table is empty
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1903
			return false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1904
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1905
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1906
		$row = $this->fetchrow();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1907
		$this->free_result();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1908
		return array_keys($row);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1909
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1910
	
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
  1911
	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
  1912
	{
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1913
		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
  1914
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1915
			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
  1916
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1917
		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
  1918
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1919
			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
  1920
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1921
	}
1207
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1922
	
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1923
	/**
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1924
 	* Returns the number of rows affected.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1925
 	* @return int
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1926
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1927
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1928
	function sql_affectedrows()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1929
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1930
		return pg_affected_rows($this->latest_result);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1931
	}
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
  1932
1227
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1933
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1934
 	* Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1935
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1936
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1937
	function sql_report()
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1938
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1939
		global $db, $session, $paths, $template, $plugins; // Common objects
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1940
		if ( !$session->get_permissions('mod_misc') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1941
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1942
			die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1943
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1944
		// Create copies of variables that may be changed after header is called
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1945
		$backtrace = $this->query_backtrace;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1946
		$times = $this->query_times;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1947
		$template->header();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1948
		echo '<h3>SQL query log and timetable</h3>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1949
		echo '<div class="tblholder">
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1950
						<table border="0" cellspacing="1" cellpadding="4">';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1951
		$i = 0;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1952
		foreach ( $backtrace as $query )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1953
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1954
			$i++;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1955
			$unbuffered = false;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1956
			if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1957
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1958
				$query = substr($query, 13);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1959
				$unbuffered = true;
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1960
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1961
			if ( $i == 1 )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1962
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1963
				echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1964
								<th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1965
							</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1966
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1967
			else
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1968
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1969
				echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1970
								<th class="subhead" colspan="2">&nbsp;</th>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1971
							</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1972
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1973
			echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1974
							<td class="row2">Query:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1975
							<td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1976
						</tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1977
						<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1978
							<td class="row2">Time:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1979
							<td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1980
						</tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1981
						<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1982
							<td class="row2">Unbuffered:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1983
							<td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1984
						</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1985
			if ( isset($this->query_sources[$query]) )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1986
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1987
				echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1988
								<td class="row2">Called from:</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1989
								<td class="row1">' . $this->query_sources[$query] . '</td>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1990
							</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1991
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1992
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1993
		if ( function_exists('array_sum') )
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1994
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1995
			$query_time_total = array_sum($this->query_times);
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1996
			echo '<tr>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1997
							<th class="subhead" colspan="2">
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1998
								Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1999
							</th>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  2000
						</tr>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  2001
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  2002
		echo '  </table>
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  2003
					</div>';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  2004
		$template->footer();
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  2005
	}
1342
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2006
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2007
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2008
	 * Begin transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2009
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2010
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2011
	function transaction_begin()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2012
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2013
		$this->sql_query('BEGIN;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2014
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2015
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2016
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2017
	 * Commit transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2018
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2019
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2020
	function transaction_commit()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2021
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2022
		$this->sql_query('COMMIT;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2023
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2024
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2025
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2026
	 * Rollback transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2027
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2028
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2029
	function transaction_rollback()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2030
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2031
		$this->sql_query('ROLLBACK;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  2032
	}
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
  2033
}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  2034
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  2035
?>