includes/dbal.php
author Dan Fuhry <dan@enanocms.org>
Mon, 24 Nov 2014 14:57:33 -0500
changeset 1381 6b25c6bfd246
parent 1378 e58294b867c1
permissions -rw-r--r--
Fix https url generation
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
1378
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    35
/**
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    36
 * Checks to see if a given pdo driver is available.
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    37
 * @param string driver name
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    38
 * @return bool
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    39
 */
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    40
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    41
function have_pdo($driver)
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    42
{
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    43
	return class_exists('PDO') && extension_loaded("pdo_$driver") && class_exists("{$driver}_pdo");
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    44
}
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    45
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    46
global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    47
$db_sql_parse_time = 0;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    48
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    49
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
    50
	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
    51
	var $row = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
	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
    53
	var $errhandler;
1378
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
    54
	var $dbms_name = 'MySQL (legacy)';
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
    55
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
    58
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
    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
		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
    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
 	* 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
    67
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
    70
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
    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
			$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
    74
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
    79
 	* @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
    80
 	*/
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    81
 
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
    82
	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
    83
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
    85
			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
    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
		$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
    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
		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
    90
			// 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
    91
			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
    92
		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
    93
			// 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
    94
			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
    95
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
    97
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   101
 	* @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
   102
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   105
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		@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
   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
		$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
   109
		$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
   110
		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
   111
			$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
   112
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   114
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
   116
		$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
   117
										? ', 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
   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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   121
											<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
   122
											<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
   123
											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
   124
											<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
   125
											<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
   126
		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
   127
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   131
 	* @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
   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
	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
   135
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   137
		$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
   138
		$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
   139
		$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
   140
		$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
   141
		$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
   142
		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
   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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   146
 	* 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
   147
 	* @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
   148
 	* @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
   149
 	* @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
   150
 	* @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
   151
 	* @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
   152
 	* @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
   153
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   154
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   155
	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
   156
	{
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   157
		if ( !function_exists('mysql_connect') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   158
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   159
			if ( class_exists('PDO') && extension_loaded("pdo_mysql") )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   160
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   161
				$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
   162
									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
   163
								<pre>$dbdriver = \'mysql\';</pre>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   164
								<p>and change it to:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   165
								<pre>$dbdriver = \'mysql_pdo\';</pre>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   166
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   167
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   168
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   169
				$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
   170
									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
   171
									the line that says:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   172
								<pre>$dbdriver = \'mysql\';</pre>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   173
								<p>and change it to:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   174
								<pre>$dbdriver = \'mysql_pdo\';</pre>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   175
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   176
			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
   177
								driver from newer versions.</p>' . $pdo_string .
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   178
								'<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
   179
									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
   180
									driver.</p>');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   181
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   182
		
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
   183
		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
   184
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   186
			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
   187
			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
   188
			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
   189
			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
   190
			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
   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 ( !$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
   194
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 ( 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
   196
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				@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
   198
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   200
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				@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
   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
			
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   205
				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
   206
			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
   207
				$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
   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
			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
   210
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				// 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
   212
				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
   213
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					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
   215
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
						$_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
   217
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					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
   219
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
						// 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
   221
						$_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
   222
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					$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
   224
					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
   225
					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
   226
					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
   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
				$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
   229
				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
   230
				$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
   231
				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
   232
				$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
   233
				$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
   234
				// 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
   235
				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
   236
				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
   237
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   238
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   239
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   240
		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
   241
			$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
   242
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   243
		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
   244
			$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
   245
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   246
		$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
   247
		
1369
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   248
		// 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
   249
		// 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
   250
		$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
   251
		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
   252
		{
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   253
			$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
   254
			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
   255
			{
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   256
				// 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
   257
				$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
   258
				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
   259
			}
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
   260
		}
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
   261
		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
   262
		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
   263
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   265
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   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
		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
   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
			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
   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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
   274
		$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
   275
		$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
   276
		$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
   277
		$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
   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
		$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
   280
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   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
		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
   284
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   286
				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
   287
			$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
   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
		// 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
   291
		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
   292
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   296
 	* @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
   297
 	* @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
   298
 	* @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
   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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   302
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   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
			$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
   306
			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
   307
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
   309
				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
   310
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 ( $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
   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
						$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
   314
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
   317
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   319
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   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
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
   325
			$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
   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
		// 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
   328
		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
   329
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
   331
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
   333
		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
   334
			$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
   335
		// 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
   336
		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
   337
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   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->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
   341
				$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
   342
				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
   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
		$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
   347
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   349
			$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
   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
		$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
   352
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   354
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   358
 	* @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
   359
 	* @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
   360
 	* @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
   361
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   364
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   366
		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
   367
			$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
   368
		$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
   369
		// 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
   370
		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
   371
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
   373
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
   375
		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
   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
			$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
   378
			$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
   379
			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
   380
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   383
		$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
   384
		$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
   385
		$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
   386
		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
   387
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   391
 	* @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
   392
 	* @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
   393
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	function check_query($q, $debug = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   396
	{
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
   397
		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
   398
		$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
   399
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
   401
		$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
   402
		$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
   403
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
   405
		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
   406
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
   408
			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
   409
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				// 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
   411
				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
   412
				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
   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
			// 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
   415
			$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
   416
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   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
		// 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
   420
		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
   421
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 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
   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
		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
   426
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
   428
			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
   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
		$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
   432
		$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
   433
		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
   434
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   438
 	* @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
   439
 	* @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
   440
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   441
 	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   442
	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
   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
		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
   445
		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
   446
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   447
			$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
   448
			$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
   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
		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
   451
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
   453
			$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
   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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   457
		$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
   458
 																										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
   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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   463
 	* @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
   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 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
   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
		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
   469
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   470
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   471
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   472
 	* 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
   473
 	* @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
   474
 	* @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
   475
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   476
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   477
	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
   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
		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
   480
			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
   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
		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
   483
			$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
   484
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   485
		if ( !$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
   486
			$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
   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
		$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
   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
		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
   491
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   493
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   494
 	* 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
   495
 	* @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
   496
 	* @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
   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
	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
   500
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   502
			$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
   503
		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
   504
			$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
   505
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   507
		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
   508
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   512
 	* @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
   513
 	* @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
   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
	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
   517
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
   519
			$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
   520
		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
   521
			$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
   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
		return mysql_num_rows($r);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   524
	}
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
   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
 	* 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
   528
 	* @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
   529
 	* @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
   530
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
   533
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
   535
		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
   536
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   537
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   538
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
   540
 	* @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
   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
	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
   545
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   546
		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
   547
			$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
   548
		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
   549
			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
   550
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   551
		@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
   552
		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
   553
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   554
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
   555
	/**
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   556
	* Get MySQL server version
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   557
	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   558
	*/
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
	function get_server_version()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   561
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   562
		return mysql_get_server_info();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   563
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   564
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   565
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   566
 	* Close the database connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   567
 	*/
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
	function close()
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
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   572
			return;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   573
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   574
		// anything we locked should certainly be unlocked now;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   575
		@mysql_query("COMMIT;", $this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   576
		@mysql_query("UNLOCK TABLES;", $this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   577
		@mysql_close($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   578
		unset($this->_conn);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   579
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   580
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   581
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   582
 	* Get a list of columns in the given table
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   583
 	* @param string Table
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   584
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   585
 	*/
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
	function columns_in($table)
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
		if ( !is_string($table) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   590
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   591
		$q = $this->sql_query("SHOW COLUMNS IN $table;");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   592
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   593
			$this->_die();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   594
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   595
		$columns = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   596
		while ( $row = $this->fetchrow_num() )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   597
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   598
			$columns[] = $row[0];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   599
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   600
		return $columns;
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   604
 	* Get the text of the most recent error.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   605
 	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   606
 	*/
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
	function sql_error()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   609
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   610
		return mysql_error();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   611
	}
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   614
 	* 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
   615
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   616
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   617
	function sql_report()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   618
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   619
		global $db, $session, $paths, $template, $plugins; // Common objects
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   620
		if ( !$session->get_permissions('mod_misc') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   621
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   622
			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
   623
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   624
		// 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
   625
		$backtrace = $this->query_backtrace;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   626
		$times = $this->query_times;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   627
		$template->header();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   628
		echo '<h3>SQL query log and timetable</h3>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   629
		echo '<div class="tblholder">
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   630
						<table border="0" cellspacing="1" cellpadding="4">';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   631
		$i = 0;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   632
		foreach ( $backtrace as $query )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   633
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   634
			$i++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   635
			$unbuffered = false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   636
			if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
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
				$query = substr($query, 13);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   639
				$unbuffered = true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   640
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   641
			if ( $i == 1 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   642
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   643
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   644
								<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
   645
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   646
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   647
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   648
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   649
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   650
								<th class="subhead" colspan="2">&nbsp;</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   651
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   652
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   653
			echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   654
							<td class="row2">Query:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   655
							<td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   656
						</tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   657
						<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   658
							<td class="row2">Time:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   659
							<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
   660
						</tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   661
						<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   662
							<td class="row2">Unbuffered:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   663
							<td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   664
						</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   665
			if ( isset($this->query_sources[$query]) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   666
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   667
				echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   668
								<td class="row2">Called from:</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   669
								<td class="row1">' . $this->query_sources[$query] . '</td>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   670
							</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   671
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   672
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   673
		if ( function_exists('array_sum') )
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
			$query_time_total = array_sum($this->query_times);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   676
			echo '<tr>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   677
							<th class="subhead" colspan="2">
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   678
								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
   679
							</th>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   680
						</tr>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   681
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   682
		echo '  </table>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   683
					</div>';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   684
		$template->footer();
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
	
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
	 * Begin transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   689
	 */
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
	function transaction_begin()
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
		$this->sql_query('BEGIN;');
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
	
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
	 * Commit transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   698
	 */
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
	function transaction_commit()
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
		$this->sql_query('COMMIT;');
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   705
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   706
	 * Rollback transaction
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   707
	 */
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   708
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   709
	function transaction_rollback()
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
		$this->sql_query('ROLLBACK;');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   712
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   713
}
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
class mysql_pdo {
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   716
	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
   717
	var $row = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   718
	var $rowset = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   719
	var $errhandler;
1378
e58294b867c1 Add transparent support for PDO into installer; further integration of PDO
Dan Fuhry <dan@enanocms.org>
parents: 1377
diff changeset
   720
	var $dbms_name = 'MySQL/PDO';
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   721
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   722
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   723
 	* 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
   724
 	*/
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
	function sql_backtrace()
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
		return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
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
 	* 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
   733
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   734
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   735
	function ensure_connection()
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
		if(!$this->_conn)
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
			$this->connect();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   740
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   741
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   742
	
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
 	* 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
   745
 	* @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
   746
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   747
 
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   748
	function _die($t = '')
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   749
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   750
		if ( defined('ENANO_HEADERS_SENT') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   751
			ob_clean();
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
		$internal_text = $this->get_error($t);
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
		if ( defined('ENANO_CONFIG_FETCHED') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   756
			// 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
   757
			die_semicritical('Database error', $internal_text);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   758
		else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   759
			// no config, display using no-DB template engine
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   760
			grinding_halt('Database error', $internal_text);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   761
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   762
		exit;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   763
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   764
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   765
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   766
 	* 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
   767
 	* @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
   768
 	*/
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
	function get_error($t = '')
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   771
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   772
		@header('HTTP/1.1 500 Internal Server Error');
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
		$bt = $this->latest_query;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   775
		$e = htmlspecialchars($this->sql_error());
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   776
		if ( empty($e) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   777
			$e = '&lt;none&gt;';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   778
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   779
		global $email;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   780
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   781
		// 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
   782
		$email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   783
										? ', 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
   784
										: '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   785
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   786
		$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
   787
											<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
   788
											<p>Description or location of error: $t<br />
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   789
											Error returned by $this->dbms_name extension: $e</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   790
											<p>Most recent SQL query:</p>
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   791
											<pre>$bt</pre>";
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   792
		return $internal_text;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   793
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   794
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   795
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   796
 	* Exit Enano and output a JSON format datbase error.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   797
 	* @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
   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
	function die_json($loc = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   801
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   802
		$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
   803
		$q = str_replace("\n", "\\n", addslashes($this->latest_query));
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   804
		$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
   805
		$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
   806
		$loc = str_replace("\n", "\\n", $loc);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   807
		$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
   808
		die($t);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   809
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   810
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   811
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   812
 	* Connect to the database.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   813
 	* @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
   814
 	* @param string Database server hostname
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   815
 	* @param string Database server username
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   816
 	* @param string Database server password
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   817
 	* @param string Name of the database
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   818
 	* @param int Optional port number to connect over
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   819
 	*/
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
	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
   822
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   823
		if ( !defined('ENANO_SQL_CONSTANTS') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   824
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   825
			define('ENANO_SQL_CONSTANTS', '');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   826
			define('ENANO_DBLAYER', 'MYSQL');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   827
			define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   828
			define('ENANO_SQL_MULTISTRING_PRFIX', '');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   829
			define('ENANO_SQL_BOOLEAN_TRUE', 'true');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   830
			define('ENANO_SQL_BOOLEAN_FALSE', 'false');
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 ( !$manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   834
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   835
			if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   836
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   837
				@include(ENANO_ROOT.'/config.new.php');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   838
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   839
			else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   840
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   841
				@include(ENANO_ROOT.'/config.php');
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
			
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   844
			if ( isset($crypto_key) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   845
				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
   846
			if ( empty($dbport) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   847
				$dbport = 3306;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   848
			
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   849
			if ( !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
   850
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   851
				// 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
   852
				if ( !defined('scriptPath') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   853
				{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   854
					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
   855
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   856
						$_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
   857
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   858
					if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   859
					{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   860
						// 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
   861
						$_SERVER['REQUEST_URI'] .= '/index.php';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   862
					}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   863
					$sp = dirname($_SERVER['REQUEST_URI']);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   864
					if($sp == '/' || $sp == '\\') $sp = '';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   865
					define('scriptPath', $sp);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   866
					define('contentPath', "$sp/index.php?title=");
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
				$loc = scriptPath . '/install/index.php';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   869
				define('IN_ENANO_INSTALL', 1);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   870
				$GLOBALS['lang'] = new Language('eng');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   871
				global $lang;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   872
				$lang->load_file('./language/english/core.json');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   873
				$lang->load_file('./language/english/install.json');
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   874
				// header("Location: $loc");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   875
				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
   876
				exit;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   877
			}
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
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   880
		if ( !$dbport )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   881
			$dbport = 3306;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   882
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   883
		if ( $dbhost && !empty($dbport) && $dbport != 3306 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   884
			$dbhost = '127.0.0.1';
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
		$host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
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
		$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
   889
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   890
		unset($dbuser);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   891
		unset($dbpasswd); // Security
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   892
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   893
		if ( !$this->_conn && !$manual_credentials )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   894
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   895
			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
   896
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   897
		else if ( !$this->_conn && $manual_credentials )
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
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   900
		}
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
		// Reset some variables
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   903
		$this->query_backtrace = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   904
		$this->query_times = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   905
		$this->query_sources = array();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   906
		$this->num_queries = 0;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   907
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   908
		$this->debug = ( defined('ENANO_DEBUG') );
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
		// We're in!
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   911
		return true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   912
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   913
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   914
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   915
 	* Make a SQL query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   916
 	* @param string Query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   917
 	* @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
   918
 	* @return resource or false on failure
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
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   921
	function sql_query($q, $log_query = true)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   922
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   923
		if ( $this->debug && function_exists('debug_backtrace') )
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
			$backtrace = @debug_backtrace();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   926
			if ( is_array($backtrace) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   927
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   928
				$bt = $backtrace[0];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   929
				if ( isset($backtrace[1]['class']) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   930
				{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   931
					if ( $backtrace[1]['class'] == 'sessionManager' )
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
						$bt = $backtrace[1];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   934
					}
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
				$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
   937
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   938
			unset($backtrace);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   939
		}
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
		$this->num_queries++;
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
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   944
			$this->query_backtrace[] = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   945
			$this->latest_query = $q;
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
		// First make sure we have a connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   948
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   949
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   950
			$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
   951
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   952
		// Start the timer
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   953
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   954
			$time_start = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   955
		// Does this query look malicious?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   956
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   957
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   958
			if ( !$this->check_query($q) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   959
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   960
				$this->report_query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   961
				$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
   962
				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
   963
			}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   964
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   965
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   966
		try
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   967
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   968
			$r = $this->_conn->query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   969
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   970
		catch ( PDOException $e )
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
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   973
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   974
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   975
		if ( $log_query )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   976
			$this->query_times[$q] = microtime_float() - $time_start;
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
		$this->latest_result = $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   979
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   980
		return $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   981
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   982
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   983
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   984
 	* 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
   985
 	* @param string Query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   986
 	* @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
   987
 	* @return resource or false on failure
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   988
 	*/
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
	function sql_unbuffered_query($q, $log_query = true)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   991
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   992
		$this->num_queries++;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   993
		if ( $log_query || defined('ENANO_DEBUG') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   994
			$this->query_backtrace[] = '(UNBUFFERED) ' . $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   995
		$this->latest_query = $q;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   996
		// First make sure we have a connection
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   997
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   998
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
   999
			$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
  1000
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1001
		// Does this query look malicious?
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1002
		if ( !$this->check_query($q) )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1003
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1004
			$this->report_query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1005
			$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
  1006
			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
  1007
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1008
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1009
		$time_start = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1010
		try
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
			$r = $this->_conn->query($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1013
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1014
		catch ( PDOException $e )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1015
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1016
			return false;
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
		$this->query_times[$q] = microtime_float() - $time_start;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1019
		$this->latest_result = $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1020
		return $r;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1021
	}
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1024
 	* 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
  1025
 	* @param string $q the query to check
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1026
 	* @return bool true if query passed check, otherwise false
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1027
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1028
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1029
	function check_query($q, $debug = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1030
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1031
		global $db_sql_parse_time;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1032
		$ts = microtime_float();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1033
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1034
		// remove properly escaped quotes
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1035
		$q = str_replace('\\\\', '', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1036
		$q = str_replace(array("\\\"", "\\'"), '', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1037
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1038
		// make sure quotes match
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1039
		foreach ( array("'", '"') as $quote )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1040
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1041
			$n_quotes = get_char_count($q, $quote);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1042
			if ( $n_quotes % 2 == 1 )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1043
			{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1044
				// mismatched quotes
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1045
				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
  1046
				return false;
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
			// 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
  1049
			$q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1050
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1051
		$q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
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
		// 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
  1054
		if ( strstr($q, '--') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1055
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1056
			return false;
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
		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
  1060
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1061
			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
  1062
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1063
		}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1064
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1065
		$ts = microtime_float() - $ts;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1066
		$db_sql_parse_time += $ts;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1067
		return true;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1068
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1069
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1070
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1071
 	* Reports a bad query to the admin
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1072
 	* @param string $query the naughty query
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1073
 	* @access private
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
 	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1076
	function report_query($query)
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
		global $session;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1079
		if ( is_object($session) && defined('ENANO_MAINSTREAM') )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1080
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1081
			$username = $session->username;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1082
			$user_id = $session->user_id;
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
		else
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1085
		{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1086
			$username = 'Unavailable';
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1087
			$user_id = 1;
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
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1090
		$query = $this->escape($query);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1091
		$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
  1092
 																										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
  1093
	}
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
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1096
 	* Returns the ID of the row last inserted.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1097
 	* @return int
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
	function insert_id()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1101
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1102
		$q = $this->sql_query("SELECT LAST_INSERT_ID();");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1103
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1104
			return false;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1105
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1106
		list($iid) = $this->fetchrow_num();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1107
		return $iid;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1108
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1109
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1110
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1111
 	* 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
  1112
 	* @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
  1113
 	* @return array
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1114
 	*/
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
	function fetchrow($r = false)
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
		if ( !$this->_conn )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1119
			return false;
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
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1122
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1123
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1124
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1125
			$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
  1126
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1127
		$row = $r->fetch(PDO::FETCH_ASSOC);
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
		return integerize_array($row);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1130
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1131
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1132
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1133
 	* 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
  1134
 	* @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
  1135
 	* @return array
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
	function fetchrow_num($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1139
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1140
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1141
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1142
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1143
			$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
  1144
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1145
		$row = $r->fetch(PDO::FETCH_NUM);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1146
		return integerize_array($row);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1147
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1148
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1149
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1150
 	* Get the number of results for a given query.
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1151
 	* @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
  1152
 	* @return array
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
	function numrows($r = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1156
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1157
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1158
			$r = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1159
		if ( !$r )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1160
			$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
  1161
		
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1162
		return $r->rowCount();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1163
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1164
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1165
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1166
 	* 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
  1167
 	* @param string String to escape
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1168
 	* @return string Escaped string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1169
 	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1170
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1171
	function escape($str)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1172
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1173
		$str = substr($this->_conn->quote($str), 1, -1);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1174
		return $str;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1175
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1176
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1177
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1178
 	* 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
  1179
 	* @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
  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
	function free_result($result = false)
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1184
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1185
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1186
			$result = $this->latest_result;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1187
		if ( !$result )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1188
			return null;
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
		//@mysql_free_result($result);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1191
		return null;
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1192
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1193
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1194
	/**
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1195
	* Get MySQL server version
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1196
	* @return string
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1197
	*/
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1198
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1199
	function get_server_version()
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1200
	{
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1201
		$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
  1202
		if ( !$q )
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1203
			$this->_die("while fetching MySQL server version");
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1204
		$row = $this->fetchrow($q);
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1205
		return $row['Value'];
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1206
	}
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1207
	
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1208
	/**
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
  1209
 	* 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
  1210
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1213
	{
1369
cfce82063776 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down
Dan Fuhry <dan@enanocms.org>
parents: 1342
diff changeset
  1214
		// 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
  1215
		$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
  1216
		$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
  1217
		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
  1218
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1222
 	* @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
  1223
 	* @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
  1224
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1229
			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
  1230
		$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
  1231
		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
  1232
			$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
  1233
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1235
		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
  1236
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1238
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1239
		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
  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
 	* 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
  1244
 	* @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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1248
	{
1375
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1249
		list(,,$errtext) = $this->_conn->errorInfo();
d66e43ac35b6 Add PDO support for MySQL
Dan Fuhry <dan@enanocms.org>
parents: 1369
diff changeset
  1250
		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
  1251
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1255
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1258
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1260
		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
  1261
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1263
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1264
		// 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
  1265
		$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
  1266
		$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
  1267
		$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
  1268
		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
  1269
		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
  1270
						<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
  1271
		$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
  1272
		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
  1273
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1275
			$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
  1276
			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
  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
				$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
  1279
				$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
  1280
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1281
			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
  1282
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1283
				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
  1284
								<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
  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
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1288
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				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
  1290
								<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
  1291
							</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
  1292
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1294
							<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
  1295
							<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
  1296
						</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
						<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
  1298
							<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
  1299
							<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
  1300
						</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
  1301
						<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
  1302
							<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
  1303
							<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
  1304
						</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
  1305
			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
  1306
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				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
  1308
								<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
  1309
								<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
  1310
							</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
  1311
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1314
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1315
			$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
  1316
			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
  1317
							<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
  1318
								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
  1319
							</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
  1320
						</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
  1321
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1322
		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
  1323
					</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
  1324
		$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
  1325
	}
1342
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1326
	
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
	 * Begin transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1329
	 */
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
	function transaction_begin()
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
		$this->sql_query('BEGIN;');
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
	
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
	 * Commit transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1338
	 */
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
	function transaction_commit()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1341
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1342
		$this->sql_query('COMMIT;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1343
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1344
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1345
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1346
	 * Rollback transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1347
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1348
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1349
	function transaction_rollback()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1350
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1351
		$this->sql_query('ROLLBACK;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1352
	}
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1353
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1354
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1355
class postgresql
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1356
{
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
  1357
	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
  1358
	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
  1359
	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
  1360
	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
  1361
	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
  1362
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1365
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1366
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  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
 	* 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
  1374
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1377
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  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
			$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
  1381
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1386
 	* @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
  1387
 	*/
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1388
 
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
  1389
	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
  1390
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1392
			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
  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
		$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
  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
		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
  1397
			// 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
  1398
			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
  1399
		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
  1400
			// 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
  1401
			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
  1402
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1404
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1406
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1407
 	* 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
  1408
 	* @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
  1409
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1410
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1411
	function 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
  1412
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1413
		@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
  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
		$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
  1416
		$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
  1417
		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
  1418
			$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
  1419
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1420
		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
  1421
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1422
		// 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
  1423
		$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
  1424
										? ', 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
  1425
										: '';
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1426
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1427
		$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
  1428
											<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
  1429
											<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
  1430
											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
  1431
											<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
  1432
											<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
  1433
		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
  1434
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1435
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1438
 	* @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
  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
	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
  1442
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1444
		$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
  1445
		$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
  1446
		$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
  1447
		$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
  1448
		$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
  1449
		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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1454
 	* @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
  1455
 	* @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
  1456
 	* @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
  1457
 	* @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
  1458
 	* @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
  1459
 	* @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
  1460
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1463
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1464
		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
  1465
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1466
			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
  1467
			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
  1468
			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
  1469
			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
  1470
			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
  1471
			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
  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 ( !$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
  1475
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 ( 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
  1477
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				@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
  1479
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1480
			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
  1481
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				@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
  1483
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1484
				
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1485
			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
  1486
				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
  1487
			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
  1488
				$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
  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
			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
  1491
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				// 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
  1493
				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
  1494
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1495
					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
  1496
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1497
						$_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
  1498
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					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
  1500
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
						// 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
  1502
						$_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
  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
					$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
  1505
					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
  1506
					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
  1507
					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
  1508
				}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1510
				// 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
  1511
				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
  1512
				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
  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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1517
			$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
  1518
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1520
		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
  1521
		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
  1522
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1524
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  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
		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
  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
			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
  1530
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1533
		$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
  1534
		$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
  1535
		$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
  1536
		$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
  1537
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  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
		// 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
  1541
		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
  1542
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1543
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1544
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1545
 	* 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
  1546
 	* @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
  1547
 	* @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
  1548
 	* @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
  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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1552
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1553
		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
  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
			$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
  1556
			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
  1557
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1558
				$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
  1559
				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
  1560
				{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
					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
  1562
					{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1563
						$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
  1564
					}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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->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
  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
			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
  1569
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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->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
  1572
		$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
  1573
		$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
  1574
		// 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
  1575
		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
  1576
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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->_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
  1578
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		// 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
  1580
		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
  1581
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1582
			$this->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
  1583
			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
  1584
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1587
		$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
  1588
		$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
  1589
		$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
  1590
		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
  1591
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1595
 	* @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
  1596
 	* @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
  1597
 	* @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
  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 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
  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
		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
  1603
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1607
 	* @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
  1608
 	* @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
  1609
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1610
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1614
		$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
  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
		// 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
  1617
		$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
  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
		// 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
  1620
		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
  1621
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 ( 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
  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
				// 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
  1625
				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
  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
			// 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
  1628
			$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
  1629
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1630
		$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
  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
		// 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
  1633
		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
  1634
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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 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
  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
		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
  1639
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1641
			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
  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
		$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
  1645
		$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
  1646
		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
  1647
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1648
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1649
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1650
 	* 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
  1651
 	* @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
  1652
 	* @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
  1653
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1654
 	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1655
	function 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
  1656
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1657
		global $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
  1658
		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
  1659
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1660
			$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
  1661
			$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
  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
		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
  1664
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1666
			$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
  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
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1670
		$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
  1671
 																										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
  1672
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1673
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1674
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1676
 	* @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
  1677
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1678
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1679
	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
  1680
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1681
		// 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
  1682
		// 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
  1683
		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
  1684
		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
  1685
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			$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
  1687
				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
  1688
				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
  1689
				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
  1690
				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
  1691
				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
  1692
				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
  1693
				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
  1694
				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
  1695
				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
  1696
				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
  1697
				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
  1698
				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
  1699
				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
  1700
				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
  1701
				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
  1702
				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
  1703
				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
  1704
				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
  1705
				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
  1706
				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
  1707
				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
  1708
				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
  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
			// 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
  1711
			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
  1712
			$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
  1713
			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
  1714
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1715
				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
  1716
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1719
		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
  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
			// 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
  1722
			$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
  1723
			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
  1724
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				$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
  1726
				$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
  1727
				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
  1728
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1729
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1730
		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
  1731
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1733
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1734
 	* 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
  1735
 	* @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
  1736
 	* @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
  1737
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1738
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1739
	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
  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
		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
  1742
			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
  1743
		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
  1744
			$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
  1745
		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
  1746
			$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
  1747
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1749
		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
  1750
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1754
 	* @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
  1755
 	* @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
  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
	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
  1759
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1761
			$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
  1762
		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
  1763
			$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
  1764
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		$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
  1766
		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
  1767
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1771
 	* @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
  1772
 	* @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
  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
	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
  1776
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1778
			$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
  1779
		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
  1780
			$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
  1781
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1782
		$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
  1783
		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
  1784
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1788
 	* @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
  1789
 	* @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
  1790
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1791
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1793
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1794
		$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
  1795
		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
  1796
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1800
 	* @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
  1801
 	* @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
  1802
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1807
			$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
  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
		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
  1810
			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
  1811
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1812
		@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
  1813
		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
  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
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1818
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1819
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1821
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		@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
  1823
		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
  1824
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1825
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1826
	/**
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
 	* 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
  1828
 	* @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
  1829
 	* @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
  1830
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1831
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  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
		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
  1835
			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
  1836
		$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
  1837
		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
  1838
			$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
  1839
		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
  1840
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1841
			// 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
  1842
			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
  1843
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1844
		
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1845
		$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
  1846
		$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
  1847
		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
  1848
	}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1849
	
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
  1850
	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
  1851
	{
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1852
		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
  1853
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1854
			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
  1855
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1856
		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
  1857
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1858
			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
  1859
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1860
	}
1207
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1861
	
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1862
	/**
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
  1863
 	* 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
  1864
 	*/
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1865
	
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
	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
  1867
	{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1869
		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
  1870
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1872
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1873
		// 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
  1874
		$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
  1875
		$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
  1876
		$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
  1877
		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
  1878
		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
  1879
						<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
  1880
		$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
  1881
		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
  1882
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1883
			$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
  1884
			$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
  1885
			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
  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
				$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
  1888
				$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
  1889
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1891
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1892
				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
  1893
								<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
  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
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
			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
  1897
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				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
  1899
								<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
  1900
							</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
  1901
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1902
			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
  1903
							<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
  1904
							<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
  1905
						</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
						<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
  1907
							<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
  1908
							<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
  1909
						</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
  1910
						<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
  1911
							<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
  1912
							<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
  1913
						</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
  1914
			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
  1915
			{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
				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
  1917
								<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
  1918
								<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
  1919
							</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
  1920
			}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser 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
		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
  1923
		{
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1924
			$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
  1925
			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
  1926
							<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
  1927
								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
  1928
							</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
  1929
						</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
  1930
		}
bdac73ed481e Going ahead with the switch to tabs. This is a major coding standards change! If any unusual parser bugs show up, check this changeset. Converted all .php, .js, .tpl, .css, and .json files and did basic testing.
Dan
parents: 1207
diff changeset
  1931
		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
  1932
					</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
  1933
		$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
  1934
	}
1342
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1935
	
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
	 * Begin transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1938
	 */
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
	function transaction_begin()
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
		$this->sql_query('BEGIN;');
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
	
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
	 * Commit transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1947
	 */
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
	function transaction_commit()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1950
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1951
		$this->sql_query('COMMIT;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1952
	}
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1953
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1954
	/**
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1955
	 * Rollback transaction
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1956
	 */
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1957
	
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1958
	function transaction_rollback()
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1959
	{
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1960
		$this->sql_query('ROLLBACK;');
2164d18cb10c Added database transaction API. (Untested with Postgres)
Dan Fuhry <dan@enanocms.org>
parents: 1227
diff changeset
  1961
	}
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
  1962
}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1963
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1964
?>