punbb/include/dblayer/mysql.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('mysql_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 MySQL support built in. MySQL support is required if you want to use a MySQL 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, $p_connect)
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
		if ($p_connect)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    46
			$this->link_id = @mysql_pconnect($db_host, $db_username, $db_password);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    47
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    48
			$this->link_id = @mysql_connect($db_host, $db_username, $db_password);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    49
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    50
		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
    51
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    52
			if (@mysql_select_db($db_name, $this->link_id))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    53
				return $this->link_id;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    54
			else
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 select database. MySQL reported: '.mysql_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
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    58
			error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    59
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    60
		// 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
    61
		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
    62
			mysql_query('SET NAMES \'utf8\'', $this->link_id) 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
    63
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    66
	function start_transaction()
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
		return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    69
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    72
	function end_transaction()
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
		return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    75
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    78
	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
    79
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    80
		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
    81
			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
    82
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    83
		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
    84
			$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
    85
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    86
		if ($unbuffered)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    87
			$this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    88
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    89
			$this->query_result = @mysql_query($sql, $this->link_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    90
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    91
		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
    92
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    93
			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
    94
				$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
    95
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    96
			++$this->num_queries;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    97
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
    98
			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
    99
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   100
		else
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
			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
   103
				$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
   104
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   105
			return false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   106
		}
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
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
	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
   111
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   112
		$sql = '';
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
		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
   115
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   116
			$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
   117
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   118
			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
   119
			{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   120
				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
   121
					$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
   122
			}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   123
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['WHERE']))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   125
				$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
   126
			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
   127
				$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
   128
			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
   129
				$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
   130
			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
   131
				$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
   132
			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
   133
				$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
   134
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   135
		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
   136
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   137
			$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
   138
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   139
			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
   140
				$sql .= ' ('.$query['INSERT'].')';
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
			$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
   143
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   144
		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
   145
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   146
			$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
   147
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   148
			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
   149
				$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
   150
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   151
			$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
   152
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   153
			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
   154
				$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
   155
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   156
		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
   157
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   158
			$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
   159
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   160
			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
   161
				$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
   162
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   163
		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
   164
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   165
			$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
   166
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   167
			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
   168
				$sql .= ' ('.$query['REPLACE'].')';
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
			$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
   171
		}
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
		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
   174
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   175
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   176
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   177
	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
   178
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   179
		return ($query_id) ? @mysql_result($query_id, $row) : false;
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   182
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   183
	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
   184
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   185
		return ($query_id) ? @mysql_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
   186
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   189
	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
   190
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   191
		return ($query_id) ? @mysql_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
   192
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   195
	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
   196
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   197
		return ($query_id) ? @mysql_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
   198
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   201
	function affected_rows()
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
		return ($this->link_id) ? @mysql_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
   204
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   207
	function insert_id()
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
		return ($this->link_id) ? @mysql_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
   210
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   213
	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
   214
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   215
		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
   216
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   219
	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
   220
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   221
		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
   222
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   225
	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
   226
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   227
		return ($query_id) ? @mysql_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
   228
	}
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
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   231
	function escape($str)
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
		if (is_array($str))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   234
			return '';
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   235
		else if (function_exists('mysql_real_escape_string'))
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   236
			return mysql_real_escape_string($str, $this->link_id);
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   237
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   238
			return mysql_escape_string($str);
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
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
	function error()
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   243
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   244
		$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
   245
		$result['error_no'] = @mysql_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
   246
		$result['error_msg'] = @mysql_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
   247
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   248
		return $result;
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
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
	function close()
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->link_id)
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   255
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   256
			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
   257
				@mysql_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
   258
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   259
			return @mysql_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
   260
		}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   261
		else
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   262
			return false;
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
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
	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
   267
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   268
		$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
   269
		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
   270
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   271
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
	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
   274
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   275
		$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
   276
		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
   277
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   278
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
	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
   281
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   282
		$exists = false;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   283
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   284
		$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
   285
		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
   286
		{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   287
			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
   288
			{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   289
				$exists = true;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   290
				break;
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
		}
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
		return $exists;
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
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
	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
   299
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   300
		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
   301
			return;
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   302
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   303
		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
   304
			$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
   305
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   306
		$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
   307
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   308
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
	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
   311
	{
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   312
		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
   313
			return;
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
		$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
   316
	}
98bbc533541c Finishing re-add, addremove didn't work last time. Integrated with Enano's template engine properly.
Dan
parents:
diff changeset
   317
}