Problem with comparison.
/Forum/db/db2.php
0,0 → 1,421
<?php
/***************************************************************************
* db2.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: db2.php,v 1.2 2002/01/28 17:24:45 psotfx Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","db2");
 
class sql_db
{
 
var $db_connect_id;
var $query_result;
var $query_resultset;
var $query_numrows;
var $next_id;
var $row = array();
var $rowset = array();
var $row_index;
var $num_queries = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->dbname = $database;
 
$this->server = $sqlserver;
 
if($this->persistency)
{
$this->db_connect_id = odbc_pconnect($this->server, "", "");
}
else
{
$this->db_connect_id = odbc_connect($this->server, "", "");
}
 
if($this->db_connect_id)
{
@odbc_autocommit($this->db_connect_id, off);
 
return $this->db_connect_id;
}
else
{
return false;
}
}
//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
if($this->query_result)
{
@odbc_free_result($this->query_result);
}
$result = @odbc_close($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
 
 
//
// Query method
//
function sql_query($query = "", $transaction = FALSE)
{
//
// Remove any pre-existing queries
//
unset($this->query_result);
unset($this->row);
if($query != "")
{
$this->num_queries++;
 
if(!eregi("^INSERT ",$query))
{
if(eregi("LIMIT", $query))
{
preg_match("/^(.*)LIMIT ([0-9]+)[, ]*([0-9]+)*/s", $query, $limits);
 
$query = $limits[1];
if($limits[3])
{
$row_offset = $limits[2];
$num_rows = $limits[3];
}
else
{
$row_offset = 0;
$num_rows = $limits[2];
}
 
$query .= " FETCH FIRST ".($row_offset+$num_rows)." ROWS ONLY OPTIMIZE FOR ".($row_offset+$num_rows)." ROWS";
 
$this->query_result = odbc_exec($this->db_connect_id, $query);
 
$query_limit_offset = $row_offset;
$this->result_numrows[$this->query_result] = $num_rows;
}
else
{
$this->query_result = odbc_exec($this->db_connect_id, $query);
 
$row_offset = 0;
$this->result_numrows[$this->query_result] = 5E6;
}
 
$result_id = $this->query_result;
if($this->query_result && eregi("^SELECT", $query))
{
 
for($i = 1; $i < odbc_num_fields($result_id)+1; $i++)
{
$this->result_field_names[$result_id][] = odbc_field_name($result_id, $i);
}
 
$i = $row_offset + 1;
$k = 0;
while(odbc_fetch_row($result_id, $i) && $k < $this->result_numrows[$result_id])
{
 
for($j = 1; $j < count($this->result_field_names[$result_id])+1; $j++)
{
$this->result_rowset[$result_id][$k][$this->result_field_names[$result_id][$j-1]] = odbc_result($result_id, $j);
}
$i++;
$k++;
}
 
$this->result_numrows[$result_id] = $k;
$this->row_index[$result_id] = 0;
}
else
{
$this->result_numrows[$result_id] = @odbc_num_rows($result_id);
$this->row_index[$result_id] = 0;
}
}
else
{
if(eregi("^(INSERT|UPDATE) ", $query))
{
$query = preg_replace("/\\\'/s", "''", $query);
}
 
$this->query_result = odbc_exec($this->db_connect_id, $query);
 
if($this->query_result)
{
$sql_id = "VALUES(IDENTITY_VAL_LOCAL())";
 
$id_result = odbc_exec($this->db_connect_id, $sql_id);
if($id_result)
{
$row_result = odbc_fetch_row($id_result);
if($row_result)
{
$this->next_id[$this->query_result] = odbc_result($id_result, 1);
}
}
}
 
odbc_commit($this->db_connect_id);
 
$this->query_limit_offset[$this->query_result] = 0;
$this->result_numrows[$this->query_result] = 0;
}
 
return $this->query_result;
}
else
{
return false;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
return $this->result_numrows[$query_id];
}
else
{
return false;
}
}
function sql_affectedrows($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
return $this->result_numrows[$query_id];
}
else
{
return false;
}
}
function sql_numfields($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = count($this->result_field_names[$query_id]);
return $result;
}
else
{
return false;
}
}
function sql_fieldname($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = $this->result_field_names[$query_id][$offset];
return $result;
}
else
{
return false;
}
}
function sql_fieldtype($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @odbc_field_type($query_id, $offset);
return $result;
}
else
{
return false;
}
}
function sql_fetchrow($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
if($this->row_index[$query_id] < $this->result_numrows[$query_id])
{
$result = $this->result_rowset[$query_id][$this->row_index[$query_id]];
$this->row_index[$query_id]++;
return $result;
}
else
{
return false;
}
}
else
{
return false;
}
}
function sql_fetchrowset($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$this->row_index[$query_id] = $this->result_numrows[$query_id];
return $this->result_rowset[$query_id];
}
else
{
return false;
}
}
function sql_fetchfield($field, $row = -1, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
if($row < $this->result_numrows[$query_id])
{
if($row == -1)
{
$getrow = $this->row_index[$query_id]-1;
}
else
{
$getrow = $row;
}
 
return $this->result_rowset[$query_id][$getrow][$this->result_field_names[$query_id][$field]];
 
}
else
{
return false;
}
}
else
{
return false;
}
}
function sql_rowseek($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$this->row_index[$query_id] = 0;
return true;
}
else
{
return false;
}
}
function sql_nextid($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
return $this->next_id[$query_id];
}
else
{
return false;
}
}
function sql_freeresult($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @odbc_free_result($query_id);
return $result;
}
else
{
return false;
}
}
function sql_error($query_id = 0)
{
// $result['code'] = @odbc_error($this->db_connect_id);
// $result['message'] = @odbc_errormsg($this->db_connect_id);
 
return "";
}
 
} // class sql_db
 
} // if ... define
 
?>
/Forum/db/index.htm
0,0 → 1,10
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body bgcolor="#FFFFFF" text="#000000">
 
</body>
</html>
/Forum/db/msaccess.php
0,0 → 1,389
<?php
/***************************************************************************
* msaccess.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: msaccess.php,v 1.8.2.2 2002/09/28 12:50:59 psotfx Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","msaccess");
 
class sql_db
{
 
var $db_connect_id;
var $result_ids = array();
var $result;
 
var $next_id;
 
var $num_rows = array();
var $current_row = array();
var $field_names = array();
var $field_types = array();
var $result_rowset = array();
 
var $num_queries = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->server = $sqlserver;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->dbname = $database;
 
$this->db_connect_id = ($this->persistency) ? odbc_pconnect($this->server, $this->user, $this->password) : odbc_connect($this->server, $this->user, $this->password);
 
return ( $this->db_connect_id ) ? $this->db_connect_id : false;
}
//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
if( $this->in_transaction )
{
@odbc_commit($this->db_connect_id);
}
 
if( count($this->result_rowset) )
{
unset($this->result_rowset);
unset($this->field_names);
unset($this->field_types);
unset($this->num_rows);
unset($this->current_row);
}
 
return @odbc_close($this->db_connect_id);
}
else
{
return false;
}
}
 
//
// Query method
//
function sql_query($query = "", $transaction = FALSE)
{
if( $query != "" )
{
$this->num_queries++;
 
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
if( !odbc_autocommit($this->db_connect_id, false) )
{
return false;
}
$this->in_transaction = TRUE;
}
 
$query = str_replace("LOWER(", "LCASE(", $query);
 
if( preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits) )
{
$query = $limits[1];
 
if( !empty($limits[2]) )
{
$row_offset = ( $limits[4] ) ? $limits[3] : "";
$num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
 
$query = "TOP " . ( $row_offset + $num_rows ) . $query;
}
 
$this->result = odbc_exec($this->db_connect_id, "SELECT $query");
 
if( $this->result )
{
if( empty($this->field_names[$this->result]) )
{
for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++)
{
$this->field_names[$this->result][] = odbc_field_name($this->result, $i);
$this->field_types[$this->result][] = odbc_field_type($this->result, $i);
}
}
 
$this->current_row[$this->result] = 0;
$this->result_rowset[$this->result] = array();
 
$row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1;
$row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9;
$row_inner = 0;
 
while( odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max )
{
for($j = 0; $j < count($this->field_names[$this->result]); $j++)
{
$this->result_rowset[$this->result][$row_inner][$this->field_names[$this->result][$j]] = stripslashes(odbc_result($this->result, $j + 1));
}
 
$row_outer++;
$row_inner++;
}
 
$this->num_rows[$this->result] = count($this->result_rowset[$this->result]);
 
odbc_free_result($this->result);
}
 
}
else if( eregi("^INSERT ", $query) )
{
$this->result = odbc_exec($this->db_connect_id, $query);
 
if( $this->result )
{
$result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
if( $result_id )
{
if( odbc_fetch_row($result_id) )
{
$this->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
}
}
else
{
$this->result = odbc_exec($this->db_connect_id, $query);
 
if( $this->result )
{
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
 
if( !$this->result )
{
if( $this->in_transaction )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
$this->in_transaction = FALSE;
}
 
return false;
}
 
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if ( !@odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
 
return $this->result;
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if ( !@odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
 
return true;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? $this->num_rows[$query_id] : false;
}
 
function sql_numfields($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? count($this->field_names[$query_id]) : false;
}
 
function sql_fieldname($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? $this->field_names[$query_id][$offset] : false;
}
 
function sql_fieldtype($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? $this->field_types[$query_id][$offset] : false;
}
 
function sql_fetchrow($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
return ( $this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false;
}
else
{
return false;
}
}
 
function sql_fetchrowset($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false;
}
else
{
return false;
}
}
 
function sql_fetchfield($field, $row = -1, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
if( $row < $this->num_rows[$query_id] )
{
$getrow = ($row == -1) ? $this->current_row[$query_id] - 1 : $row;
 
return $this->result_rowset[$query_id][$getrow][$this->field_names[$query_id][$field]];
}
else
{
return false;
}
}
else
{
return false;
}
}
 
function sql_rowseek($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
$this->current_row[$query_id] = $offset - 1;
return true;
}
else
{
return false;
}
}
 
function sql_nextid()
{
return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
}
 
function sql_affectedrows()
{
return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false;
}
 
function sql_freeresult($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
unset($this->num_rows[$query_id]);
unset($this->current_row[$query_id]);
unset($this->result_rowset[$query_id]);
unset($this->field_names[$query_id]);
unset($this->field_types[$query_id]);
 
return true;
}
 
function sql_error()
{
$error['code'] = "";//odbc_error($this->db_connect_id);
$error['message'] = "Error";//odbc_errormsg($this->db_connect_id);
 
return $error;
}
 
} // class sql_db
 
} // if ... define
 
?>
/Forum/db/mssql-odbc.php
0,0 → 1,387
<?php
/***************************************************************************
* mssql-odbc.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: mssql-odbc.php,v 1.7 2002/03/20 17:48:30 psotfx Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","mssql-odbc");
 
class sql_db
{
 
var $db_connect_id;
var $result;
 
var $next_id;
 
var $num_rows = array();
var $current_row = array();
var $field_names = array();
var $field_types = array();
var $result_rowset = array();
 
var $num_queries = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->server = $sqlserver;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->dbname = $database;
 
$this->db_connect_id = ($this->persistency) ? odbc_pconnect($this->server, $this->user, $this->password) : odbc_connect($this->server, $this->user, $this->password);
 
return ( $this->db_connect_id ) ? $this->db_connect_id : false;
}
//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
if( $this->in_transaction )
{
@odbc_commit($this->db_connect_id);
}
 
if( count($this->result_rowset) )
{
unset($this->result_rowset);
unset($this->field_names);
unset($this->field_types);
unset($this->num_rows);
unset($this->current_row);
}
 
return @odbc_close($this->db_connect_id);
}
else
{
return false;
}
}
 
//
// Query method
//
function sql_query($query = "", $transaction = FALSE)
{
if( $query != "" )
{
$this->num_queries++;
 
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
if( !odbc_autocommit($this->db_connect_id, false) )
{
return false;
}
$this->in_transaction = TRUE;
}
 
if( preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits) )
{
$query = $limits[1];
 
if( !empty($limits[2]) )
{
$row_offset = ( $limits[4] ) ? $limits[3] : "";
$num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
 
$query = "TOP " . ( $row_offset + $num_rows ) . $query;
}
 
$this->result = odbc_exec($this->db_connect_id, "SELECT $query");
 
if( $this->result )
{
if( empty($this->field_names[$this->result]) )
{
for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++)
{
$this->field_names[$this->result][] = odbc_field_name($this->result, $i);
$this->field_types[$this->result][] = odbc_field_type($this->result, $i);
}
}
 
$this->current_row[$this->result] = 0;
$this->result_rowset[$this->result] = array();
 
$row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1;
$row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9;
$row_inner = 0;
 
while( odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max )
{
for($j = 0; $j < count($this->field_names[$this->result]); $j++)
{
$this->result_rowset[$this->result][$row_inner][$this->field_names[$this->result][$j]] = stripslashes(odbc_result($this->result, $j + 1));
}
 
$row_outer++;
$row_inner++;
}
 
$this->num_rows[$this->result] = count($this->result_rowset[$this->result]);
}
 
}
else if( eregi("^INSERT ", $query) )
{
$this->result = odbc_exec($this->db_connect_id, $query);
 
if( $this->result )
{
$result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
if( $result_id )
{
if( odbc_fetch_row($result_id) )
{
$this->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
}
}
else
{
$this->result = odbc_exec($this->db_connect_id, $query);
 
if( $this->result )
{
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
 
if( !$this->result )
{
if( $this->in_transaction )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
$this->in_transaction = FALSE;
}
 
return false;
}
 
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if ( !odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
 
odbc_free_result($this->result);
 
return $this->result;
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if ( !@odbc_commit($this->db_connect_id) )
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
return false;
}
odbc_autocommit($this->db_connect_id, true);
}
 
return true;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? $this->num_rows[$query_id] : false;
}
 
function sql_numfields($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? count($this->field_names[$query_id]) : false;
}
 
function sql_fieldname($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? $this->field_names[$query_id][$offset] : false;
}
 
function sql_fieldtype($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? $this->field_types[$query_id][$offset] : false;
}
 
function sql_fetchrow($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
return ( $this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false;
}
else
{
return false;
}
}
 
function sql_fetchrowset($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false;
}
else
{
return false;
}
}
 
function sql_fetchfield($field, $row = -1, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
if( $row < $this->num_rows[$query_id] )
{
$getrow = ( $row == -1 ) ? $this->current_row[$query_id] - 1 : $row;
 
return $this->result_rowset[$query_id][$getrow][$this->field_names[$query_id][$field]];
 
}
else
{
return false;
}
}
else
{
return false;
}
}
 
function sql_rowseek($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
$this->current_row[$query_id] = $offset - 1;
return true;
}
else
{
return false;
}
}
 
function sql_nextid()
{
return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
}
 
function sql_affectedrows()
{
return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false;
}
 
function sql_freeresult($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
unset($this->num_rows[$query_id]);
unset($this->current_row[$query_id]);
unset($this->result_rowset[$query_id]);
unset($this->field_names[$query_id]);
unset($this->field_types[$query_id]);
 
return true;
}
 
function sql_error()
{
$error['code'] = odbc_error($this->db_connect_id);
$error['message'] = odbc_errormsg($this->db_connect_id);
 
return $error;
}
 
} // class sql_db
 
} // if ... define
 
?>
/Forum/db/mssql.php
0,0 → 1,418
<?php
/***************************************************************************
* mssql.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : supportphpbb.com
*
* $Id: mssql.php,v 1.22.2.4 2006/03/09 19:57:37 grahamje Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","mssql");
 
class sql_db
{
 
var $db_connect_id;
var $result;
 
var $next_id;
var $in_transaction = 0;
 
var $row = array();
var $rowset = array();
var $limit_offset;
var $query_limit_success;
 
var $num_queries = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->server = $sqlserver;
$this->dbname = $database;
 
$this->db_connect_id = ( $this->persistency ) ? @mssql_pconnect($this->server, $this->user, $this->password) : @mssql_connect($this->server, $this->user, $this->password);
 
if( $this->db_connect_id && $this->dbname != "" )
{
if( !mssql_select_db($this->dbname, $this->db_connect_id) )
{
mssql_close($this->db_connect_id);
return false;
}
}
 
return $this->db_connect_id;
}
 
//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
//
// Commit any remaining transactions
//
if( $this->in_transaction )
{
@mssql_query("COMMIT", $this->db_connect_id);
}
 
return @mssql_close($this->db_connect_id);
}
else
{
return false;
}
}
 
 
//
// Query method
//
function sql_query($query = '', $transaction = FALSE)
{
//
// Remove any pre-existing queries
//
unset($this->result);
unset($this->row);
 
if ( $query != '' )
{
$this->num_queries++;
 
if ( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
if ( !@mssql_query('BEGIN TRANSACTION', $this->db_connect_id) )
{
return false;
}
$this->in_transaction = TRUE;
}
 
//
// Does query contain any LIMIT code? If so pull out relevant start and num_results
// This isn't terribly easy with MSSQL, whatever you do will potentially impact
// performance compared to an 'in-built' limit
//
// Another issue is the 'lack' of a returned true value when a query is valid but has
// no result set (as with all the other DB interfaces). It seems though that it's
// 'fair' to say that if a query returns a false result (ie. no resource id) then the
// SQL was valid but had no result set. If the query returns nothing but the rowcount
// returns something then there's a problem. This may well be a false assumption though
// ... needs checking under Windows itself.
//
if( preg_match('#^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$#s', $query, $limits) )
{
$query = $limits[1];
 
if( !empty($limits[2]) )
{
$row_offset = ( $limits[4] ) ? $limits[3] : "";
$num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
 
$query = 'TOP ' . ( $row_offset + $num_rows ) . $query;
}
 
$this->result = @mssql_query("SELECT $query", $this->db_connect_id);
 
if( $this->result )
{
$this->limit_offset[$this->result] = ( !empty($row_offset) ) ? $row_offset : 0;
 
if( $row_offset > 0 )
{
@mssql_data_seek($this->result, $row_offset);
}
}
}
else if( preg_match('#^INSERT #i', $query) )
{
if( @mssql_query($query, $this->db_connect_id) )
{
$this->result = time() + microtime();
 
$result_id = @mssql_query('SELECT @@IDENTITY AS id, @@ROWCOUNT as affected', $this->db_connect_id);
if( $result_id )
{
if( $row = @mssql_fetch_array($result_id) )
{
$this->next_id[$this->db_connect_id] = $row['id'];
$this->affected_rows[$this->db_connect_id] = $row['affected'];
}
}
}
}
else
{
if( @mssql_query($query, $this->db_connect_id) )
{
$this->result = time() + microtime();
 
$result_id = @mssql_query('SELECT @@ROWCOUNT as affected', $this->db_connect_id);
if( $result_id )
{
if( $row = @mssql_fetch_array($result_id) )
{
$this->affected_rows[$this->db_connect_id] = $row['affected'];
}
}
}
}
 
if( !$this->result )
{
if( $this->in_transaction )
{
@mssql_query('ROLLBACK', $this->db_connect_id);
$this->in_transaction = FALSE;
}
 
return false;
}
 
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if( !@mssql_query('COMMIT', $this->db_connect_id) )
{
@mssql_query("ROLLBACK", $this->db_connect_id);
return false;
}
}
 
return $this->result;
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if( !@mssql_query('COMMIT', $this->db_connect_id) )
{
@mssql_query('ROLLBACK', $this->db_connect_id);
return false;
}
}
 
return true;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
return ( !empty($this->limit_offset[$query_id]) ) ? @mssql_num_rows($query_id) - $this->limit_offset[$query_id] : @mssql_num_rows($query_id);
}
else
{
return false;
}
}
 
function sql_numfields($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? @mssql_num_fields($query_id) : false;
}
 
function sql_fieldname($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? @mssql_field_name($query_id, $offset) : false;
}
 
function sql_fieldtype($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->result;
}
 
return ( $query_id ) ? @mssql_field_type($query_id, $offset) : false;
}
 
function sql_fetchrow($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
empty($row);
 
$row = @mssql_fetch_array($query_id);
 
while( list($key, $value) = @each($row) )
{
$row[$key] = ($value === ' ') ? '' : stripslashes($value);
}
@reset($row);
 
return $row;
}
else
{
return false;
}
}
 
function sql_fetchrowset($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
$i = 0;
empty($rowset);
 
while( $row = @mssql_fetch_array($query_id))
{
while( list($key, $value) = @each($row) )
{
$rowset[$i][$key] = ($value === ' ') ? '' : stripslashes($value);
}
$i++;
}
@reset($rowset);
 
return $rowset;
}
else
{
return false;
}
}
 
function sql_fetchfield($field, $row = -1, $query_id)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
if( $row != -1 )
{
if( $this->limit_offset[$query_id] > 0 )
{
$result = ( !empty($this->limit_offset[$query_id]) ) ? @mssql_result($this->result, ($this->limit_offset[$query_id] + $row), $field) : false;
}
else
{
$result = @mssql_result($this->result, $row, $field);
}
}
else
{
if( empty($this->row[$query_id]) )
{
$this->row[$query_id] = @mssql_fetch_array($query_id);
$result = ($this->row[$query_id][$field] === ' ') ? '' : stripslashes($this->row[$query_id][$field]);
}
}
 
return $result;
}
else
{
return false;
}
}
 
function sql_rowseek($rownum, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
if( $query_id )
{
return ( !empty($this->limit_offset[$query_id]) ) ? @mssql_data_seek($query_id, ($this->limit_offset[$query_id] + $rownum)) : @mssql_data_seek($query_id, $rownum);
}
else
{
return false;
}
}
 
function sql_nextid()
{
return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
}
 
function sql_affectedrows()
{
return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false;
}
 
function sql_freeresult($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->result;
}
 
return ( $query_id ) ? @mssql_free_result($query_id) : false;
}
 
function sql_error($query_id = 0)
{
$result['message'] = @mssql_get_last_message();
return $result;
}
 
} // class sql_db
 
} // if ... define
 
?>
/Forum/db/mysql.php
0,0 → 1,335
<?php
/***************************************************************************
* mysql.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: mysql.php,v 1.16.2.1 2005/09/18 16:17:20 acydburn Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","mysql");
 
class sql_db
{
 
var $db_connect_id;
var $query_result;
var $row = array();
var $rowset = array();
var $num_queries = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
 
$this->persistency = $persistency;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->server = $sqlserver;
$this->dbname = $database;
 
if($this->persistency)
{
$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password);
}
else
{
$this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password);
}
if($this->db_connect_id)
{
if($database != "")
{
$this->dbname = $database;
$dbselect = @mysql_select_db($this->dbname);
if(!$dbselect)
{
@mysql_close($this->db_connect_id);
$this->db_connect_id = $dbselect;
}
}
return $this->db_connect_id;
}
else
{
return false;
}
}
 
//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
if($this->query_result)
{
@mysql_free_result($this->query_result);
}
$result = @mysql_close($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
 
//
// Base query method
//
function sql_query($query = "", $transaction = FALSE)
{
// Remove any pre-existing queries
unset($this->query_result);
if($query != "")
{
$this->num_queries++;
 
$this->query_result = @mysql_query($query, $this->db_connect_id);
}
if($this->query_result)
{
unset($this->row[$this->query_result]);
unset($this->rowset[$this->query_result]);
return $this->query_result;
}
else
{
return ( $transaction == END_TRANSACTION ) ? true : false;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_num_rows($query_id);
return $result;
}
else
{
return false;
}
}
function sql_affectedrows()
{
if($this->db_connect_id)
{
$result = @mysql_affected_rows($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
function sql_numfields($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_num_fields($query_id);
return $result;
}
else
{
return false;
}
}
function sql_fieldname($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_field_name($query_id, $offset);
return $result;
}
else
{
return false;
}
}
function sql_fieldtype($offset, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_field_type($query_id, $offset);
return $result;
}
else
{
return false;
}
}
function sql_fetchrow($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$this->row[$query_id] = @mysql_fetch_array($query_id);
return $this->row[$query_id];
}
else
{
return false;
}
}
function sql_fetchrowset($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
unset($this->rowset[$query_id]);
unset($this->row[$query_id]);
while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
{
$result[] = $this->rowset[$query_id];
}
return $result;
}
else
{
return false;
}
}
function sql_fetchfield($field, $rownum = -1, $query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
if($rownum > -1)
{
$result = @mysql_result($query_id, $rownum, $field);
}
else
{
if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
{
if($this->sql_fetchrow())
{
$result = $this->row[$query_id][$field];
}
}
else
{
if($this->rowset[$query_id])
{
$result = $this->rowset[$query_id][0][$field];
}
else if($this->row[$query_id])
{
$result = $this->row[$query_id][$field];
}
}
}
return $result;
}
else
{
return false;
}
}
function sql_rowseek($rownum, $query_id = 0){
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = @mysql_data_seek($query_id, $rownum);
return $result;
}
else
{
return false;
}
}
function sql_nextid(){
if($this->db_connect_id)
{
$result = @mysql_insert_id($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
function sql_freeresult($query_id = 0){
if(!$query_id)
{
$query_id = $this->query_result;
}
 
if ( $query_id )
{
unset($this->row[$query_id]);
unset($this->rowset[$query_id]);
 
@mysql_free_result($query_id);
 
return true;
}
else
{
return false;
}
}
function sql_error($query_id = 0)
{
$result["message"] = @mysql_error($this->db_connect_id);
$result["code"] = @mysql_errno($this->db_connect_id);
 
return $result;
}
 
} // class sql_db
 
} // if ... define
 
?>
/Forum/db/mysql4.php
0,0 → 1,340
<?php
/***************************************************************************
* mysql4.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : supportphpbb.com
*
* $Id: mysql4.php,v 1.5.2.1 2005/09/18 16:17:20 acydburn Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","mysql4");
 
class sql_db
{
 
var $db_connect_id;
var $query_result;
var $row = array();
var $rowset = array();
var $num_queries = 0;
var $in_transaction = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->server = $sqlserver;
$this->dbname = $database;
 
$this->db_connect_id = ($this->persistency) ? mysql_pconnect($this->server, $this->user, $this->password) : mysql_connect($this->server, $this->user, $this->password);
 
if( $this->db_connect_id )
{
if( $database != "" )
{
$this->dbname = $database;
$dbselect = mysql_select_db($this->dbname);
 
if( !$dbselect )
{
mysql_close($this->db_connect_id);
$this->db_connect_id = $dbselect;
}
}
 
return $this->db_connect_id;
}
else
{
return false;
}
}
 
//
// Other base methods
//
function sql_close()
{
if( $this->db_connect_id )
{
//
// Commit any remaining transactions
//
if( $this->in_transaction )
{
mysql_query("COMMIT", $this->db_connect_id);
}
 
return mysql_close($this->db_connect_id);
}
else
{
return false;
}
}
 
//
// Base query method
//
function sql_query($query = "", $transaction = FALSE)
{
//
// Remove any pre-existing queries
//
unset($this->query_result);
 
if( $query != "" )
{
$this->num_queries++;
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
$result = mysql_query("BEGIN", $this->db_connect_id);
if(!$result)
{
return false;
}
$this->in_transaction = TRUE;
}
 
$this->query_result = mysql_query($query, $this->db_connect_id);
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$result = mysql_query("COMMIT", $this->db_connect_id);
}
}
 
if( $this->query_result )
{
unset($this->row[$this->query_result]);
unset($this->rowset[$this->query_result]);
 
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if ( !mysql_query("COMMIT", $this->db_connect_id) )
{
mysql_query("ROLLBACK", $this->db_connect_id);
return false;
}
}
return $this->query_result;
}
else
{
if( $this->in_transaction )
{
mysql_query("ROLLBACK", $this->db_connect_id);
$this->in_transaction = FALSE;
}
return false;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? mysql_num_rows($query_id) : false;
}
 
function sql_affectedrows()
{
return ( $this->db_connect_id ) ? mysql_affected_rows($this->db_connect_id) : false;
}
 
function sql_numfields($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? mysql_num_fields($query_id) : false;
}
 
function sql_fieldname($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? mysql_field_name($query_id, $offset) : false;
}
 
function sql_fieldtype($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? mysql_field_type($query_id, $offset) : false;
}
 
function sql_fetchrow($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if( $query_id )
{
$this->row[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC);
return $this->row[$query_id];
}
else
{
return false;
}
}
 
function sql_fetchrowset($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if( $query_id )
{
unset($this->rowset[$query_id]);
unset($this->row[$query_id]);
 
while($this->rowset[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC))
{
$result[] = $this->rowset[$query_id];
}
 
return $result;
}
else
{
return false;
}
}
 
function sql_fetchfield($field, $rownum = -1, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if( $query_id )
{
if( $rownum > -1 )
{
$result = mysql_result($query_id, $rownum, $field);
}
else
{
if( empty($this->row[$query_id]) && empty($this->rowset[$query_id]) )
{
if( $this->sql_fetchrow() )
{
$result = $this->row[$query_id][$field];
}
}
else
{
if( $this->rowset[$query_id] )
{
$result = $this->rowset[$query_id][0][$field];
}
else if( $this->row[$query_id] )
{
$result = $this->row[$query_id][$field];
}
}
}
 
return $result;
}
else
{
return false;
}
}
 
function sql_rowseek($rownum, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? mysql_data_seek($query_id, $rownum) : false;
}
 
function sql_nextid()
{
return ( $this->db_connect_id ) ? mysql_insert_id($this->db_connect_id) : false;
}
 
function sql_freeresult($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if ( $query_id )
{
unset($this->row[$query_id]);
unset($this->rowset[$query_id]);
 
mysql_free_result($query_id);
 
return true;
}
else
{
return false;
}
}
 
function sql_error()
{
$result['message'] = mysql_error($this->db_connect_id);
$result['code'] = mysql_errno($this->db_connect_id);
 
return $result;
}
 
} // class sql_db
 
} // if ... define
 
?>
/Forum/db/postgres7.php
0,0 → 1,397
<?php
/***************************************************************************
* postgres7.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : supportphpbb.com
*
* $Id: postgres7.php,v 1.19.2.3 2005/05/06 20:50:10 acydburn Exp $
*
***************************************************************************/
 
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
 
if(!defined("SQL_LAYER"))
{
 
define("SQL_LAYER","postgresql");
 
class sql_db
{
 
var $db_connect_id;
var $query_result;
var $in_transaction = 0;
var $row = array();
var $rowset = array();
var $rownum = array();
var $num_queries = 0;
 
//
// Constructor
//
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->connect_string = "";
 
if( $sqluser )
{
$this->connect_string .= "user=$sqluser ";
}
 
if( $sqlpassword )
{
$this->connect_string .= "password=$sqlpassword ";
}
 
if( $sqlserver )
{
if( ereg(":", $sqlserver) )
{
list($sqlserver, $sqlport) = split(":", $sqlserver);
$this->connect_string .= "host=$sqlserver port=$sqlport ";
}
else
{
if( $sqlserver != "localhost" )
{
$this->connect_string .= "host=$sqlserver ";
}
}
}
 
if( $database )
{
$this->dbname = $database;
$this->connect_string .= "dbname=$database";
}
 
$this->persistency = $persistency;
 
$this->db_connect_id = ( $this->persistency ) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string);
 
return ( $this->db_connect_id ) ? $this->db_connect_id : false;
}
 
//
// Other base methods
//
function sql_close()
{
if( $this->db_connect_id )
{
//
// Commit any remaining transactions
//
if( $this->in_transaction )
{
@pg_exec($this->db_connect_id, "COMMIT");
}
 
if( $this->query_result )
{
@pg_freeresult($this->query_result);
}
 
return @pg_close($this->db_connect_id);
}
else
{
return false;
}
}
 
//
// Query method
//
function sql_query($query = "", $transaction = false)
{
//
// Remove any pre-existing queries
//
unset($this->query_result);
if( $query != "" )
{
$this->num_queries++;
 
$query = preg_replace("/LIMIT ([0-9]+),([ 0-9]+)/", "LIMIT \\2 OFFSET \\1", $query);
 
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
{
$this->in_transaction = TRUE;
 
if( !@pg_exec($this->db_connect_id, "BEGIN") )
{
return false;
}
}
 
$this->query_result = @pg_exec($this->db_connect_id, $query);
if( $this->query_result )
{
if( $transaction == END_TRANSACTION )
{
$this->in_transaction = FALSE;
 
if( !@pg_exec($this->db_connect_id, "COMMIT") )
{
@pg_exec($this->db_connect_id, "ROLLBACK");
return false;
}
}
 
$this->last_query_text[$this->query_result] = $query;
$this->rownum[$this->query_result] = 0;
 
unset($this->row[$this->query_result]);
unset($this->rowset[$this->query_result]);
 
return $this->query_result;
}
else
{
if( $this->in_transaction )
{
@pg_exec($this->db_connect_id, "ROLLBACK");
}
$this->in_transaction = FALSE;
 
return false;
}
}
else
{
if( $transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
 
if( !@pg_exec($this->db_connect_id, "COMMIT") )
{
@pg_exec($this->db_connect_id, "ROLLBACK");
return false;
}
}
 
return true;
}
}
 
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? @pg_numrows($query_id) : false;
}
 
function sql_numfields($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? @pg_numfields($query_id) : false;
}
 
function sql_fieldname($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? @pg_fieldname($query_id, $offset) : false;
}
 
function sql_fieldtype($offset, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? @pg_fieldtype($query_id, $offset) : false;
}
 
function sql_fetchrow($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if($query_id)
{
$this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]);
 
if( $this->row )
{
$this->rownum[$query_id]++;
return $this->row;
}
}
 
return false;
}
 
function sql_fetchrowset($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if( $query_id )
{
unset($this->rowset[$query_id]);
unset($this->row[$query_id]);
$this->rownum[$query_id] = 0;
 
while( $this->rowset = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC) )
{
$result[] = $this->rowset;
$this->rownum[$query_id]++;
}
 
return $result;
}
 
return false;
}
 
function sql_fetchfield($field, $row_offset=-1, $query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
if( $query_id )
{
if( $row_offset != -1 )
{
$this->row = @pg_fetch_array($query_id, $row_offset, PGSQL_ASSOC);
}
else
{
if( $this->rownum[$query_id] )
{
$this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]-1, PGSQL_ASSOC);
}
else
{
$this->row = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC);
 
if( $this->row )
{
$this->rownum[$query_id]++;
}
}
}
 
return $this->row[$field];
}
 
return false;
}
 
function sql_rowseek($offset, $query_id = 0)
{
 
if(!$query_id)
{
$query_id = $this->query_result;
}
 
if( $query_id )
{
if( $offset > -1 )
{
$this->rownum[$query_id] = $offset;
return true;
}
else
{
return false;
}
}
 
return false;
}
 
function sql_nextid()
{
$query_id = $this->query_result;
 
if($query_id && $this->last_query_text[$query_id] != "")
{
if( preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text[$query_id], $tablename) )
{
$query = "SELECT currval('" . $tablename[1] . "_id_seq') AS last_value";
$temp_q_id = @pg_exec($this->db_connect_id, $query);
if( !$temp_q_id )
{
return false;
}
 
$temp_result = @pg_fetch_array($temp_q_id, 0, PGSQL_ASSOC);
 
return ( $temp_result ) ? $temp_result['last_value'] : false;
}
}
 
return false;
}
 
function sql_affectedrows($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? @pg_cmdtuples($query_id) : false;
}
 
function sql_freeresult($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
return ( $query_id ) ? @pg_freeresult($query_id) : false;
}
 
function sql_error($query_id = 0)
{
if( !$query_id )
{
$query_id = $this->query_result;
}
 
$result['message'] = @pg_errormessage($this->db_connect_id);
$result['code'] = -1;
 
return $result;
}
 
} // class ... db_sql
 
} // if ... defined
 
?>