punbb/include/dblayer/mysqli.php
author Dan
Sun, 06 Apr 2008 00:28:50 -0400
changeset 7 98bbc533541c
permissions -rw-r--r--
Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     1
<?php
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     2
/***********************************************************************
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     3
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2008  PunBB.org
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     5
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     7
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    12
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    17
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    22
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    23
************************************************************************/
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    24
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    25
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    26
// Make sure we have built in support for MySQL
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    27
if (!function_exists('mysqli_connect'))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    28
	exit('This PHP environment doesn\'t have Improved MySQL (mysqli) support built in. Improved MySQL support is required if you want to use a MySQL 4.1 (or later) database to run this forum. Consult the PHP documentation for further assistance.');
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    29
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    30
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    31
class DBLayer
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    32
{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    33
	var $prefix;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    34
	var $link_id;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    35
	var $query_result;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    36
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    37
	var $saved_queries = array();
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    38
	var $num_queries = 0;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    39
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    40
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    41
	function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $foo)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    42
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    43
		$this->prefix = $db_prefix;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    44
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    45
		// Was a custom port supplied with $db_host?
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    46
		if (strpos($db_host, ':') !== false)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    47
			list($db_host, $db_port) = explode(':', $db_host);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    48
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    49
		if (isset($db_port))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    50
			$this->link_id = @mysqli_connect($db_host, $db_username, $db_password, $db_name, $db_port);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    51
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    52
			$this->link_id = @mysqli_connect($db_host, $db_username, $db_password, $db_name);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    53
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    54
		if (!$this->link_id)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    55
			error('Unable to connect to MySQL and select database. MySQL reported: '.mysqli_connect_error(), __FILE__, __LINE__);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    56
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    57
		// Setup the client-server character set (UTF-8)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    58
		if (!defined('PUN_NO_SET_NAMES'))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    59
			mysqli_query($this->link_id, 'SET NAMES \'utf8\'') or error(__FILE__, __LINE__);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    60
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    61
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    62
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    63
	function start_transaction()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    64
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    65
		return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    66
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    67
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    68
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    69
	function end_transaction()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    70
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    71
		return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    72
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    73
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    74
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    75
	function query($sql, $unbuffered = false)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    76
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    77
		if (strlen($sql) > 140000)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    78
			exit('Insane query. Aborting.');
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    79
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    80
		if (defined('PUN_SHOW_QUERIES'))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    81
			$q_start = get_microtime();
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    82
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    83
		$this->query_result = @mysqli_query($this->link_id, $sql);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    84
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    85
		if ($this->query_result)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    86
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    87
			if (defined('PUN_SHOW_QUERIES'))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    88
				$this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    89
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    90
			++$this->num_queries;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    91
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    92
			return $this->query_result;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    93
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    94
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    95
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    96
			if (defined('PUN_SHOW_QUERIES'))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    97
				$this->saved_queries[] = array($sql, 0);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    98
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    99
			return false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   100
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   101
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   102
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   103
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   104
	function query_build($query, $unbuffered = false)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   105
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   106
		$sql = '';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   107
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   108
		if (isset($query['SELECT']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   109
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   110
			$sql = 'SELECT '.$query['SELECT'].' FROM '.(isset($query['PARAMS']['NO_PREFIX']) ? '' : $this->prefix).$query['FROM'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   111
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   112
			if (isset($query['JOINS']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   113
			{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   114
				foreach ($query['JOINS'] as $cur_join)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   115
					$sql .= ' '.key($cur_join).' '.(isset($query['PARAMS']['NO_PREFIX']) ? '' : $this->prefix).current($cur_join).' ON '.$cur_join['ON'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   116
			}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   117
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   118
			if (!empty($query['WHERE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   119
				$sql .= ' WHERE '.$query['WHERE'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   120
			if (!empty($query['GROUP BY']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   121
				$sql .= ' GROUP BY '.$query['GROUP BY'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   122
			if (!empty($query['HAVING']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   123
				$sql .= ' HAVING '.$query['HAVING'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   124
			if (!empty($query['ORDER BY']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   125
				$sql .= ' ORDER BY '.$query['ORDER BY'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   126
			if (!empty($query['LIMIT']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   127
				$sql .= ' LIMIT '.$query['LIMIT'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   128
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   129
		else if (isset($query['INSERT']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   130
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   131
			$sql = 'INSERT INTO '.(isset($query['PARAMS']['NO_PREFIX']) ? '' : $this->prefix).$query['INTO'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   132
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   133
			if (!empty($query['INSERT']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   134
				$sql .= ' ('.$query['INSERT'].')';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   135
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   136
			$sql .= ' VALUES('.$query['VALUES'].')';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   137
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   138
		else if (isset($query['UPDATE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   139
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   140
			$query['UPDATE'] = (isset($query['PARAMS']['NO_PREFIX']) ? '' : $this->prefix).$query['UPDATE'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   141
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   142
			if (isset($query['PARAMS']['LOW_PRIORITY']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   143
				$query['UPDATE'] = 'LOW_PRIORITY '.$query['UPDATE'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   144
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   145
			$sql = 'UPDATE '.$query['UPDATE'].' SET '.$query['SET'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   146
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   147
			if (!empty($query['WHERE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   148
				$sql .= ' WHERE '.$query['WHERE'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   149
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   150
		else if (isset($query['DELETE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   151
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   152
			$sql = 'DELETE FROM '.(isset($query['PARAMS']['NO_PREFIX']) ? '' : $this->prefix).$query['DELETE'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   153
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   154
			if (!empty($query['WHERE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   155
				$sql .= ' WHERE '.$query['WHERE'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   156
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   157
		else if (isset($query['REPLACE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   158
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   159
			$sql = 'REPLACE INTO '.(isset($query['PARAMS']['NO_PREFIX']) ? '' : $this->prefix).$query['INTO'];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   160
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   161
			if (!empty($query['REPLACE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   162
				$sql .= ' ('.$query['REPLACE'].')';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   163
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   164
			$sql .= ' VALUES('.$query['VALUES'].')';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   165
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   166
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   167
		return $this->query($sql, $unbuffered);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   168
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   169
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   170
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   171
	function result($query_id = 0, $row = 0)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   172
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   173
		if ($query_id)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   174
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   175
			if ($row)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   176
				@mysqli_data_seek($query_id, $row);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   177
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   178
			$cur_row = @mysqli_fetch_row($query_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   179
			return $cur_row[0];
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   180
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   181
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   182
			return false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   183
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   184
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   185
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   186
	function fetch_assoc($query_id = 0)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   187
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   188
		return ($query_id) ? @mysqli_fetch_assoc($query_id) : false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   189
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   190
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   191
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   192
	function fetch_row($query_id = 0)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   193
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   194
		return ($query_id) ? @mysqli_fetch_row($query_id) : false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   195
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   196
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   197
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   198
	function num_rows($query_id = 0)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   199
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   200
		return ($query_id) ? @mysqli_num_rows($query_id) : false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   201
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   202
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   203
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   204
	function affected_rows()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   205
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   206
		return ($this->link_id) ? @mysqli_affected_rows($this->link_id) : false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   207
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   208
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   209
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   210
	function insert_id()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   211
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   212
		return ($this->link_id) ? @mysqli_insert_id($this->link_id) : false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   213
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   214
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   215
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   216
	function get_num_queries()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   217
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   218
		return $this->num_queries;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   219
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   220
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   221
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   222
	function get_saved_queries()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   223
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   224
		return $this->saved_queries;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   225
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   226
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   227
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   228
	function free_result($query_id = false)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   229
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   230
		return ($query_id) ? @mysqli_free_result($query_id) : false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   231
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   232
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   233
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   234
	function escape($str)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   235
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   236
		return is_array($str) ? '' : mysqli_real_escape_string($this->link_id, $str);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   237
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   238
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   239
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   240
	function error()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   241
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   242
		$result['error_sql'] = @current(@end($this->saved_queries));
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   243
		$result['error_no'] = @mysqli_errno($this->link_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   244
		$result['error_msg'] = @mysqli_error($this->link_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   245
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   246
		return $result;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   247
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   248
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   249
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   250
	function close()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   251
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   252
		if ($this->link_id)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   253
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   254
			if ($this->query_result)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   255
				@mysqli_free_result($this->query_result);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   256
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   257
			return @mysqli_close($this->link_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   258
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   259
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   260
			return false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   261
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   262
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   263
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   264
	function table_exists($table_name)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   265
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   266
		$result = $this->query('SHOW TABLES LIKE \''.$this->escape($table_name).'\'');
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   267
		return $this->num_rows($result) > 0;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   268
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   269
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   270
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   271
	function field_exists($table_name, $field_name)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   272
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   273
		$result = $this->query('SHOW COLUMNS FROM '.$table_name.' LIKE \''.$this->escape($field_name).'\'');
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   274
		return $this->num_rows($result) > 0;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   275
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   276
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   277
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   278
	function index_exists($table_name, $index_name)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   279
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   280
		$exists = false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   281
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   282
		$result = $this->query('SHOW INDEX FROM '.$table_name);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   283
		while ($cur_index = $this->fetch_assoc($result))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   284
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   285
			if ($cur_index['Key_name'] == $index_name)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   286
			{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   287
				$exists = true;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   288
				break;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   289
			}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   290
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   291
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   292
		return $exists;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   293
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   294
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   295
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   296
	function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   297
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   298
		if ($this->field_exists($table_name, $field_name))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   299
			return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   300
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   301
		if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   302
			$default_value = '\''.$this->escape($default_value).'\'';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   303
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   304
		$this->query('ALTER TABLE '.$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) or error(__FILE__, __LINE__);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   305
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   306
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   307
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   308
	function drop_field($table_name, $field_name)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   309
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   310
		if (!$this->field_exists($table_name, $field_name))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   311
			return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   312
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   313
		$this->query('ALTER TABLE '.$table_name.' DROP '.$field_name) or error(__FILE__, __LINE__);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   314
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   315
}