includes/dbal.php
author Dan Fuhry <dan@enanocms.org>
Wed, 21 Aug 2013 22:34:54 -0400
changeset 1377 fa2b0825bbc5
parent 1375 d66e43ac35b6
child 1378 e58294b867c1
permissions -rw-r--r--
Removed unused/seldom-used DBAL functions that weren't entirely supported in PDO
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
 	* 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
   427
 	* @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
   428
 	* @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
   429
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   432
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   434
		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
   435
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
   437
			$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
   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
		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
   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
			$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
   442
			$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
   443
		} 
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   446
		$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
   447
 																										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
   448
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   452
 	* @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
   453
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   456
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   458
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   462
 	* @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
   463
 	* @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
   464
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   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
		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
   469
			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
   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
		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
   472
			$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
   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
		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
   475
			$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
   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
		$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
   478
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   480
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   484
 	* @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
   485
 	* @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
   486
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   489
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   491
			$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
   492
		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
   493
			$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
   494
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   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
 	* 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
   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 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
   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
		return mysql_num_rows($r);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   513
	}
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
   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
 	* 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
   517
 	* @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
   518
 	* @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
   519
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   522
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   524
		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
   525
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   529
 	* @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
   530
 	* @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
   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
	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
   534
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   536
			$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
   537
		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
   538
			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
   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
		@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
   541
		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
   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
	/**
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   545
	* Get MySQL server version
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   546
	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   547
	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   548
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   549
	function get_server_version()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   550
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   551
		return mysql_get_server_info();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   552
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   553
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   554
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   555
 	* Close the database connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   556
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   557
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   558
	function close()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   559
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   560
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   561
			return;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   562
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   563
		// anything we locked should certainly be unlocked now;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   564
		@mysql_query("COMMIT;", $this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   565
		@mysql_query("UNLOCK TABLES;", $this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   566
		@mysql_close($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   567
		unset($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   568
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   569
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   570
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   571
 	* Get a list of columns in the given table
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   572
 	* @param string Table
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   573
 	* @return array
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 columns_in($table)
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
		if ( !is_string($table) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   579
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   580
		$q = $this->sql_query("SHOW COLUMNS IN $table;");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   581
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   582
			$this->_die();
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
		$columns = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   585
		while ( $row = $this->fetchrow_num() )
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
			$columns[] = $row[0];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   588
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   589
		return $columns;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   590
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   591
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   592
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   593
 	* Get the text of the most recent error.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   594
 	* @return string
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
	function sql_error()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   598
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   599
		return mysql_error();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   600
	}
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
 	* 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
   604
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   605
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   606
	function sql_report()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   607
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   608
		global $db, $session, $paths, $template, $plugins; // Common objects
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   609
		if ( !$session->get_permissions('mod_misc') )
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
			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
   612
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   613
		// 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
   614
		$backtrace = $this->query_backtrace;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   615
		$times = $this->query_times;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   616
		$template->header();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   617
		echo '<h3>SQL query log and timetable</h3>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   618
		echo '<div class="tblholder">
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   619
						<table border="0" cellspacing="1" cellpadding="4">';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   620
		$i = 0;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   621
		foreach ( $backtrace as $query )
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
			$i++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   624
			$unbuffered = false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   625
			if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   626
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   627
				$query = substr($query, 13);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   628
				$unbuffered = true;
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
			if ( $i == 1 )
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
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   633
								<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
   634
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   635
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   636
			else
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
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   639
								<th class="subhead" colspan="2">&nbsp;</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   640
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   641
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   642
			echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   643
							<td class="row2">Query:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   644
							<td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   645
						</tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   646
						<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   647
							<td class="row2">Time:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   648
							<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
   649
						</tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   650
						<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   651
							<td class="row2">Unbuffered:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   652
							<td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   653
						</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   654
			if ( isset($this->query_sources[$query]) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   655
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   656
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   657
								<td class="row2">Called from:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   658
								<td class="row1">' . $this->query_sources[$query] . '</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   659
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   660
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   661
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   662
		if ( function_exists('array_sum') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   663
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   664
			$query_time_total = array_sum($this->query_times);
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">
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   667
								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
   668
							</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   669
						</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   670
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   671
		echo '  </table>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   672
					</div>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   673
		$template->footer();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   674
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   675
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   676
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   677
	 * Begin transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   678
	 */
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   679
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   680
	function transaction_begin()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   681
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   682
		$this->sql_query('BEGIN;');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   683
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   684
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   685
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   686
	 * Commit transaction
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
	function transaction_commit()
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
		$this->sql_query('COMMIT;');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   692
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   693
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   694
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   695
	 * Rollback transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   696
	 */
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
	function transaction_rollback()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   699
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   700
		$this->sql_query('ROLLBACK;');
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
class mysql_pdo {
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   705
	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
   706
	var $row = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   707
	var $rowset = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   708
	var $errhandler;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   709
	var $dbms_name = 'MySQL';
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
 	* 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
   713
 	*/
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
	function sql_backtrace()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   716
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   717
		return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   718
	}
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
 	* 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
   722
 	*/
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
	function ensure_connection()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   725
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   726
		if(!$this->_conn)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   727
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   728
			$this->connect();
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   732
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   733
 	* 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
   734
 	* @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
   735
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   736
 
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   737
	function _die($t = '')
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
		if ( defined('ENANO_HEADERS_SENT') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   740
			ob_clean();
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
		$internal_text = $this->get_error($t);
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
		if ( defined('ENANO_CONFIG_FETCHED') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   745
			// 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
   746
			die_semicritical('Database error', $internal_text);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   747
		else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   748
			// no config, display using no-DB template engine
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   749
			grinding_halt('Database error', $internal_text);
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
		exit;
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
	
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
 	* 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
   756
 	* @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
   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
	function get_error($t = '')
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   760
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   761
		@header('HTTP/1.1 500 Internal Server Error');
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
		$bt = $this->latest_query;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   764
		$e = htmlspecialchars($this->sql_error());
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   765
		if ( empty($e) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   766
			$e = '&lt;none&gt;';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   767
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   768
		global $email;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   769
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   770
		// 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
   771
		$email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   772
										? ', 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
   773
										: '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   774
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   775
		$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
   776
											<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
   777
											<p>Description or location of error: $t<br />
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   778
											Error returned by $this->dbms_name extension: $e</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   779
											<p>Most recent SQL query:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   780
											<pre>$bt</pre>";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   781
		return $internal_text;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   782
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   783
	
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
 	* Exit Enano and output a JSON format datbase error.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   786
 	* @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
   787
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   788
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   789
	function die_json($loc = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   790
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   791
		$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
   792
		$q = str_replace("\n", "\\n", addslashes($this->latest_query));
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   793
		$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
   794
		$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
   795
		$loc = str_replace("\n", "\\n", $loc);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   796
		$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
   797
		die($t);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   798
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   799
	
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
 	* Connect to the database.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   802
 	* @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
   803
 	* @param string Database server hostname
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   804
 	* @param string Database server username
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   805
 	* @param string Database server password
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   806
 	* @param string Name of the database
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   807
 	* @param int Optional port number to connect over
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   808
 	*/
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
	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
   811
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   812
		if ( !defined('ENANO_SQL_CONSTANTS') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   813
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   814
			define('ENANO_SQL_CONSTANTS', '');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   815
			define('ENANO_DBLAYER', 'MYSQL');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   816
			define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   817
			define('ENANO_SQL_MULTISTRING_PRFIX', '');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   818
			define('ENANO_SQL_BOOLEAN_TRUE', 'true');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   819
			define('ENANO_SQL_BOOLEAN_FALSE', 'false');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   820
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   821
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   822
		if ( !$manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   823
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   824
			if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
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
				@include(ENANO_ROOT.'/config.new.php');
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
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   829
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   830
				@include(ENANO_ROOT.'/config.php');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   831
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   832
			
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   833
			if ( isset($crypto_key) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   834
				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
   835
			if ( empty($dbport) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   836
				$dbport = 3306;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   837
			
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   838
			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
   839
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   840
				// 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
   841
				if ( !defined('scriptPath') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   842
				{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   843
					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
   844
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   845
						$_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
   846
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   847
					if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
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
						// 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
   850
						$_SERVER['REQUEST_URI'] .= '/index.php';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   851
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   852
					$sp = dirname($_SERVER['REQUEST_URI']);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   853
					if($sp == '/' || $sp == '\\') $sp = '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   854
					define('scriptPath', $sp);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   855
					define('contentPath', "$sp/index.php?title=");
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
				$loc = scriptPath . '/install/index.php';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   858
				define('IN_ENANO_INSTALL', 1);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   859
				$GLOBALS['lang'] = new Language('eng');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   860
				global $lang;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   861
				$lang->load_file('./language/english/core.json');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   862
				$lang->load_file('./language/english/install.json');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   863
				// header("Location: $loc");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   864
				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
   865
				exit;
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
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   868
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   869
		if ( !$dbport )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   870
			$dbport = 3306;
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
		if ( $dbhost && !empty($dbport) && $dbport != 3306 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   873
			$dbhost = '127.0.0.1';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   874
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   875
		$host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   876
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   877
		$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
   878
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   879
		unset($dbuser);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   880
		unset($dbpasswd); // Security
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   881
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   882
		if ( !$this->_conn && !$manual_credentials )
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
			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
   885
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   886
		else if ( !$this->_conn && $manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   887
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   888
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   889
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   890
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   891
		// Reset some variables
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   892
		$this->query_backtrace = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   893
		$this->query_times = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   894
		$this->query_sources = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   895
		$this->num_queries = 0;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   896
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   897
		$this->debug = ( defined('ENANO_DEBUG') );
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
		// We're in!
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   900
		return true;
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
	
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
 	* Make a SQL query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   905
 	* @param string Query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   906
 	* @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
   907
 	* @return resource or false on failure
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   910
	function sql_query($q, $log_query = true)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   911
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   912
		if ( $this->debug && function_exists('debug_backtrace') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   913
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   914
			$backtrace = @debug_backtrace();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   915
			if ( is_array($backtrace) )
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
				$bt = $backtrace[0];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   918
				if ( isset($backtrace[1]['class']) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   919
				{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   920
					if ( $backtrace[1]['class'] == 'sessionManager' )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   921
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   922
						$bt = $backtrace[1];
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
				}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   925
				$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
   926
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   927
			unset($backtrace);
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
		$this->num_queries++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   931
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   932
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   933
			$this->query_backtrace[] = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   934
			$this->latest_query = $q;
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
		// First make sure we have a connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   937
		if ( !$this->_conn )
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
			$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
   940
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   941
		// Start the timer
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   942
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   943
			$time_start = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   944
		// Does this query look malicious?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   945
		if ( $log_query || defined('ENANO_DEBUG') )
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 ( !$this->check_query($q) )
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
				$this->report_query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   950
				$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
   951
				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
   952
			}
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
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   955
		try
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
			$r = $this->_conn->query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   958
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   959
		catch ( PDOException $e )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   960
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   961
			return false;
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
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   964
		if ( $log_query )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   965
			$this->query_times[$q] = microtime_float() - $time_start;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   966
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   967
		$this->latest_result = $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   968
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   969
		return $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   970
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   971
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   972
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   973
 	* 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
   974
 	* @param string Query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   975
 	* @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
   976
 	* @return resource or false on failure
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   977
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   978
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   979
	function sql_unbuffered_query($q, $log_query = true)
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
		$this->num_queries++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   982
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   983
			$this->query_backtrace[] = '(UNBUFFERED) ' . $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   984
		$this->latest_query = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   985
		// First make sure we have a connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   986
		if ( !$this->_conn )
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
			$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
   989
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   990
		// Does this query look malicious?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   991
		if ( !$this->check_query($q) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   992
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   993
			$this->report_query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   994
			$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
   995
			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
   996
		}
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
		$time_start = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   999
		try
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1000
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1001
			$r = $this->_conn->query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1002
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1003
		catch ( PDOException $e )
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
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1006
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1007
		$this->query_times[$q] = microtime_float() - $time_start;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1008
		$this->latest_result = $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1009
		return $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1010
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1011
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1012
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1013
 	* 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
  1014
 	* @param string $q the query to check
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1015
 	* @return bool true if query passed check, otherwise false
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1018
	function check_query($q, $debug = false)
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
		global $db_sql_parse_time;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1021
		$ts = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1022
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1023
		// remove properly escaped quotes
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1024
		$q = str_replace('\\\\', '', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1025
		$q = str_replace(array("\\\"", "\\'"), '', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1026
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1027
		// make sure quotes match
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1028
		foreach ( array("'", '"') as $quote )
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
			$n_quotes = get_char_count($q, $quote);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1031
			if ( $n_quotes % 2 == 1 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1032
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1033
				// mismatched quotes
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1034
				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
  1035
				return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1036
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1037
			// 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
  1038
			$q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
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
		$q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1041
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1042
		// 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
  1043
		if ( strstr($q, '--') )
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
			return 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
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1048
		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
  1049
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1050
			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
  1051
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1052
		}
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
		$ts = microtime_float() - $ts;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1055
		$db_sql_parse_time += $ts;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1056
		return true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1057
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1058
	
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
 	* Reports a bad query to the admin
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1061
 	* @param string $query the naughty query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1062
 	* @access private
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
 	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1065
	function report_query($query)
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
		global $session;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1068
		if ( is_object($session) && defined('ENANO_MAINSTREAM') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1069
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1070
			$username = $session->username;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1071
			$user_id = $session->user_id;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1072
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1073
		else
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
			$username = 'Unavailable';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1076
			$user_id = 1;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1077
		} 
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1078
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1079
		$query = $this->escape($query);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1080
		$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
  1081
 																										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
  1082
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1083
	
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
 	* Returns the ID of the row last inserted.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1086
 	* @return int
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1087
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1088
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1089
	function insert_id()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1090
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1091
		$q = $this->sql_query("SELECT LAST_INSERT_ID();");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1092
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1093
			return 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
		list($iid) = $this->fetchrow_num();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1096
		return $iid;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1097
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1098
	
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
 	* 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
  1101
 	* @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
  1102
 	* @return array
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1105
	function fetchrow($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1106
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1107
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1108
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1109
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1110
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1111
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1112
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1113
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1114
			$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
  1115
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1116
		$row = $r->fetch(PDO::FETCH_ASSOC);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1117
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1118
		return integerize_array($row);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1119
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1120
	
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
 	* 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
  1123
 	* @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
  1124
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1125
 	*/
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
	function fetchrow_num($r = false)
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
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1130
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1131
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1132
			$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
  1133
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1134
		$row = $r->fetch(PDO::FETCH_NUM);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1135
		return integerize_array($row);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1136
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1137
	
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
 	* Get the number of results for a given query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1140
 	* @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
  1141
 	* @return array
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
	function numrows($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1145
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1146
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1147
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1148
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1149
			$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
  1150
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1151
		return $r->rowCount();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1152
	}
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1155
 	* 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
  1156
 	* @param string String to escape
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1157
 	* @return string Escaped string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1158
 	*/
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
	function escape($str)
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
		$str = substr($this->_conn->quote($str), 1, -1);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1163
		return $str;
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1167
 	* 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
  1168
 	* @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
  1169
 	* @return null
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1172
	function free_result($result = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1173
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1174
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1175
			$result = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1176
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1177
			return null;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1178
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1179
		//@mysql_free_result($result);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1180
		return null;
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1184
	* Get MySQL server version
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1185
	* @return string
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 get_server_version()
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
		$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
  1191
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1192
			$this->_die("while fetching MySQL server version");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1193
		$row = $this->fetchrow($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1194
		return $row['Value'];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1195
	}
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
	/**
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
  1198
 	* 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
  1199
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1200
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1201
	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
  1202
	{
1369
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
  1203
		// anything we locked should certainly be unlocked now;
1377
fa2b0825bbc5 Removed unused/seldom-used DBAL functions that weren't entirely supported in PDO
Dan Fuhry <dan@enanocms.org>
parents: 1375
diff changeset
  1204
		$this->sql_query("COMMIT;", $this->_conn);
fa2b0825bbc5 Removed unused/seldom-used DBAL functions that weren't entirely supported in PDO
Dan Fuhry <dan@enanocms.org>
parents: 1375
diff changeset
  1205
		$this->sql_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
  1206
		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
  1207
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1208
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1209
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1210
 	* 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
  1211
 	* @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
  1212
 	* @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
  1213
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1214
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1215
	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
  1216
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1217
		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
  1218
			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
  1219
		$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
  1220
		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
  1221
			$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
  1222
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1223
		$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
  1224
		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
  1225
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1226
			$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
  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
  1228
		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
  1229
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1230
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1231
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1232
 	* 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
  1233
 	* @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
  1234
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1235
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1236
	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
  1237
	{
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1238
		list(,,$errtext) = $this->_conn->errorInfo();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1239
		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
  1240
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1241
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1242
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1243
 	* 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
  1244
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1245
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1246
	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
  1247
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1248
		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
  1249
		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
  1250
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1251
			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
  1252
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1254
		$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
  1255
		$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
  1256
		$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
  1257
		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
  1258
		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
  1259
						<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
  1260
		$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
  1261
		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
  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
			$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
  1264
			$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
  1265
			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
  1266
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1268
				$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
  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
			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
  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
				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
  1273
								<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
  1274
							</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
  1275
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
				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
  1279
								<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
  1280
							</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
  1281
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1283
							<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
  1284
							<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
  1285
						</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
  1286
						<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
  1287
							<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
  1288
							<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
  1289
						</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
  1290
						<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
  1291
							<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
  1292
							<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
  1293
						</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
  1294
			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
  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
				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
  1297
								<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
  1298
								<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
  1299
							</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
  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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1303
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1305
			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
  1306
							<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
  1307
								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
  1308
							</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
  1309
						</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
  1310
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1312
					</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
  1313
		$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
  1314
	}
1342
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1315
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1316
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1317
	 * Begin transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1318
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1319
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1320
	function transaction_begin()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1321
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1322
		$this->sql_query('BEGIN;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1323
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1324
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1325
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1326
	 * Commit transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1327
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1328
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1329
	function transaction_commit()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1330
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1331
		$this->sql_query('COMMIT;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1332
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1333
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1334
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1335
	 * Rollback transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1336
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1337
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1338
	function transaction_rollback()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1339
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1340
		$this->sql_query('ROLLBACK;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1341
	}
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1342
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1343
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1344
class postgresql
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1345
{
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
  1346
	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
  1347
	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
  1348
	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
  1349
	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
  1350
	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
  1351
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1354
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1357
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1359
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1363
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1366
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1368
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1370
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1371
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1372
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1373
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1374
 	* 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
  1375
 	* @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
  1376
 	*/
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1377
 
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
  1378
	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
  1379
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1380
		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
  1381
			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
  1382
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1383
		$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
  1384
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1385
		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
  1386
			// 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
  1387
			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
  1388
		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
  1389
			// 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
  1390
			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
  1391
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1392
		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
  1393
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1394
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1395
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1396
 	* 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
  1397
 	* @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
  1398
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1399
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1400
	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
  1401
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		@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
  1403
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1405
		$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
  1406
		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
  1407
			$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
  1408
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
		// 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
  1412
		$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
  1413
										? ', 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
  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
		$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
  1417
											<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
  1418
											<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
  1419
											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
  1420
											<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
  1421
											<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
  1422
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1427
 	* @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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1431
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1432
		$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
  1433
		$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
  1434
		$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
  1435
		$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
  1436
		$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
  1437
		$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
  1438
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1443
 	* @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
  1444
 	* @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
  1445
 	* @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
  1446
 	* @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
  1447
 	* @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
  1448
 	* @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
  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
	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
  1452
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
			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
  1456
			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
  1457
			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
  1458
			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
  1459
			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
  1460
			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
  1461
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1464
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1466
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				@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
  1468
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
				@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
  1472
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1475
				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
  1476
			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
  1477
				$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
  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
			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
  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
				// 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
  1482
				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
  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
					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
  1485
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
						$_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
  1487
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					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
  1489
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
						// 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
  1491
						$_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
  1492
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					$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
  1494
					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
  1495
					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
  1496
					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
  1497
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1499
				// 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
  1500
				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
  1501
				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
  1502
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1506
			$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
  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
		$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
  1509
		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
  1510
		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
  1511
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1513
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1515
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
			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
  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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1522
		$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
  1523
		$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
  1524
		$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
  1525
		$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
  1526
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  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
		// 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
  1530
		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
  1531
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1535
 	* @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
  1536
 	* @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
  1537
 	* @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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1541
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1543
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1545
			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
  1546
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1548
				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
  1549
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					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
  1551
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
						$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
  1553
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1556
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
		$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
  1561
		$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
  1562
		$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
  1563
		// 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
  1564
		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
  1565
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1567
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1569
		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
  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
			$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
  1572
			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
  1573
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1576
		$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
  1577
		$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
  1578
		$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
  1579
		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
  1580
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1584
 	* @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
  1585
 	* @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
  1586
 	* @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
  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
	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
  1590
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1592
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1596
 	* @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
  1597
 	* @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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1603
		$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
  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
		// 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
  1606
		$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
  1607
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1609
		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
  1610
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1612
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				// 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
  1614
				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
  1615
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 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
  1617
			$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
  1618
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  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
		// 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
  1622
		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
  1623
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
			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
  1630
			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
  1631
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1634
		$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
  1635
		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
  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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1640
 	* @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
  1641
 	* @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
  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 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
  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
		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
  1647
		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
  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
			$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
  1650
			$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
  1651
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
			$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
  1655
			$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
  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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1659
		$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
  1660
 																										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
  1661
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1665
 	* @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
  1666
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1669
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1671
		// 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
  1672
		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
  1673
		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
  1674
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1676
				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
  1677
				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
  1678
				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
  1679
				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
  1680
				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
  1681
				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
  1682
				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
  1683
				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
  1684
				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
  1685
				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
  1686
				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
  1687
				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
  1688
				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
  1689
				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
  1690
				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
  1691
				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
  1692
				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
  1693
				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
  1694
				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
  1695
				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
  1696
				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
  1697
				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
  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
			// 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
  1700
			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
  1701
			$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
  1702
			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
  1703
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				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
  1705
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1708
		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
  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
			// 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
  1711
			$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
  1712
			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
  1713
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1715
				$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
  1716
				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
  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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1724
 	* @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
  1725
 	* @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
  1726
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1731
			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
  1732
		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
  1733
			$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
  1734
		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
  1735
			$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
  1736
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1738
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1743
 	* @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
  1744
 	* @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
  1745
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1748
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1750
			$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
  1751
		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
  1752
			$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
  1753
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1755
		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
  1756
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1760
 	* @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
  1761
 	* @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
  1762
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1765
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1767
			$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
  1768
		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
  1769
			$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
  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
		$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
  1772
		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
  1773
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1777
 	* @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
  1778
 	* @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
  1779
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1782
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1784
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1789
 	* @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
  1790
 	* @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
  1791
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1796
			$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
  1797
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1799
			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
  1800
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		@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
  1802
		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
  1803
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1807
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1810
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		@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
  1812
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1817
 	* @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
  1818
 	* @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
  1819
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1822
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 ( !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
  1824
			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
  1825
		$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
  1826
		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
  1827
			$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
  1828
		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
  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
			// 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
  1831
			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
  1832
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1835
		$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
  1836
		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
  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
	
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
  1839
	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
  1840
	{
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1841
		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
  1842
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1843
			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
  1844
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1845
		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
  1846
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1847
			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
  1848
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1849
	}
1207
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1850
	
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1851
	/**
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
  1852
 	* 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
  1853
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1856
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1858
		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
  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
			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
  1861
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1863
		$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
  1864
		$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
  1865
		$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
  1866
		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
  1867
		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
  1868
						<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
  1869
		$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
  1870
		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
  1871
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1873
			$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
  1874
			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
  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
				$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
  1877
				$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
  1878
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
				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
  1882
								<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
  1883
							</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
  1884
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
				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
  1888
								<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
  1889
							</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
  1890
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1892
							<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
  1893
							<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
  1894
						</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
  1895
						<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
  1896
							<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
  1897
							<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
  1898
						</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
  1899
						<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
  1900
							<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
  1901
							<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
  1902
						</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
  1903
			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
  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
				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
  1906
								<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
  1907
								<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
  1908
							</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
  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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1911
		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
  1912
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1913
			$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
  1914
			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
  1915
							<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
  1916
								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
  1917
							</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
  1918
						</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
  1919
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1920
		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
  1921
					</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
  1922
		$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
  1923
	}
1342
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1924
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1925
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1926
	 * Begin transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1927
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1928
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1929
	function transaction_begin()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1930
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1931
		$this->sql_query('BEGIN;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1932
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1933
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1934
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1935
	 * Commit transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1936
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1937
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1938
	function transaction_commit()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1939
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1940
		$this->sql_query('COMMIT;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1941
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1942
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1943
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1944
	 * Rollback transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1945
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1946
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1947
	function transaction_rollback()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1948
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1949
		$this->sql_query('ROLLBACK;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1950
	}
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
  1951
}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1952
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1953
?>