diff options
author | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-03-17 10:54:23 +0000 |
---|---|---|
committer | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-03-17 10:54:23 +0000 |
commit | c345279596d3a54f6379c1a148b5e42bcba204cd (patch) | |
tree | d8118af490cac7866ef2909bf30545c68cceda57 /phpBB/includes | |
parent | ad7001c59ea4683dd98d9ad359d8b07830e39dce (diff) | |
download | forums-c345279596d3a54f6379c1a148b5e42bcba204cd.tar forums-c345279596d3a54f6379c1a148b5e42bcba204cd.tar.gz forums-c345279596d3a54f6379c1a148b5e42bcba204cd.tar.bz2 forums-c345279596d3a54f6379c1a148b5e42bcba204cd.tar.xz forums-c345279596d3a54f6379c1a148b5e42bcba204cd.zip |
Moved to includes ... since they are included too .. trying to "clean up" structure a little
git-svn-id: file:///svn/phpbb/trunk@3656 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/db/db2.php | 421 | ||||
-rw-r--r-- | phpBB/includes/db/firebird.php | 430 | ||||
-rw-r--r-- | phpBB/includes/db/index.htm | 10 | ||||
-rw-r--r-- | phpBB/includes/db/msaccess.php | 389 | ||||
-rw-r--r-- | phpBB/includes/db/mssql-odbc.php | 387 | ||||
-rw-r--r-- | phpBB/includes/db/mssql.php | 421 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 445 | ||||
-rw-r--r-- | phpBB/includes/db/mysql4.php | 445 | ||||
-rw-r--r-- | phpBB/includes/db/oracle.php | 472 | ||||
-rw-r--r-- | phpBB/includes/db/postgres.php | 397 |
10 files changed, 3817 insertions, 0 deletions
diff --git a/phpBB/includes/db/db2.php b/phpBB/includes/db/db2.php new file mode 100644 index 0000000000..da471841c1 --- /dev/null +++ b/phpBB/includes/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$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php new file mode 100644 index 0000000000..668298fdbd --- /dev/null +++ b/phpBB/includes/db/firebird.php @@ -0,0 +1,430 @@ +<?php +/*************************************************************************** + * mysql.php + * ------------------- + * begin : Saturday, Feb 13, 2001 + * copyright : (C) 2001 The phpBB Group + * email : support@phpbb.com + * + * $Id$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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', 'firebird'); + +class sql_db +{ + var $db_connect_id; + var $query_result; + var $return_on_error = false; + var $transaction = false; + var $sql_report = ''; + var $sql_time = 0; + var $escape_max = array('match' => array('\\', '\'', '"'), 'replace' => array('\\\\', '\'\'', '\"')); + var $escape_min = array('match' => array('\\', '"'), 'replace' => array('\\\\', '\"')); + + // Constructor + function sql_db($sqlserver, $sqluser, $sqlpassword, $database = '', $port = '', $persistency = false) + { + $this->open_queries = array(); + $this->num_queries = 0; + + $this->persistency = $persistency; + $this->user = $sqluser; + $this->password = $sqlpassword; + $this->server = $sqlserver; + + $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($this->server, $this->user, $this->password) : @ibase_connect($this->server, $this->user, $this->password); + + return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); + } + + // Other base methods + function sql_close() + { + if (!$this->db_connect_id) + { + return false; + } + + if (count($this->open_queries)) + { + foreach ($this->open_queries as $query_id) + { + @ibase_free_query($query_id); + } + } + + return @ibase_close($this->db_connect_id); + } + + function sql_return_on_error($fail = false) + { + $this->return_on_error = $fail; + } + + function sql_num_queries() + { + return $this->num_queries; + } + + function sql_transaction($status = 'begin') + { + switch ($status) + { + case 'begin': + $this->transaction = true; + $result = ibase_trans(); + break; + + case 'commit': + $result = ibase_commit(); + $this->transaction = false; + break; + + case 'rollback': + $result = ibase_rollback(); + $this->transaction = false; + break; + + default: + $result = true; + } + + return $result; + } + + // Base query method + function sql_query($query = '', $expire_time = 0) + { + if ($query != '') + { + global $cache; + + if (!$expire_time || !$cache->sql_load($query, $expire_time)) + { + if ($expire_time) + { + $cache_result = true; + } + + $this->query_result = false; + $this->num_queries++; + + if (!empty($_GET['explain'])) + { + global $starttime; + + $curtime = explode(' ', microtime()); + $curtime = $curtime[0] + $curtime[1] - $starttime; + } + + if (!($this->query_result = @ibase_query($query, $this->db_connect_id))) + { + $this->sql_error($query); + } + + if (!empty($_GET['explain'])) + { + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1] - $starttime; + + $this->sql_report .= "<pre>Query:\t" . htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n\t", $query)) . "\n\n"; + + if ($this->query_result) + { + $this->sql_report .= "Time before: $curtime\nTime after: $endtime\nElapsed time: <b>" . ($endtime - $curtime) . "</b>\n</pre>"; + } + else + { + $error = $this->sql_error(); + $this->sql_report .= '<b>FAILED</b> - MySQL Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']) . '<br><br><pre>'; + } + + $this->sql_time += $endtime - $curtime; +/* + if (preg_match('/^SELECT/', $query)) + { + $html_table = FALSE; + if ($result = mysql_query("EXPLAIN $query", $this->db_connect_id)) + { + while ($row = mysql_fetch_assoc($result)) + { + if (!$html_table && count($row)) + { + $html_table = TRUE; + $this->sql_report .= "<table width=100% border=1 cellpadding=2 cellspacing=1>\n"; + $this->sql_report .= "<tr>\n<td><b>" . implode("</b></td>\n<td><b>", array_keys($row)) . "</b></td>\n</tr>\n"; + } + $this->sql_report .= "<tr>\n<td>" . implode(" </td>\n<td>", array_values($row)) . " </td>\n</tr>\n"; + } + } + + if ($html_table) + { + $this->sql_report .= '</table><br>'; + } + } +*/ + $this->sql_report .= "<hr>\n"; + } + + $this->open_queries[] = $this->query_result; + } + + if (!empty($cache_result)) + { + $cache->sql_save($query, $this->query_result); + @ibase_free_result(array_pop($this->open_queries)); + } + } + else + { + return false; + } + + return ($this->query_result) ? $this->query_result : false; + } + + function sql_query_limit($query, $total, $offset = 0, $expire_time = 0) + { + if ($query != '') + { + $this->query_result = false; + $this->num_queries++; + + $query .= ' ROWS ' . $total . ((!empty($offset)) ? ' TO ' . $offset : ''); + + return $this->sql_query($query, $expire_time); + } + else + { + return false; + } + } + + // Idea for this from Ikonboard + function sql_build_array($query, $assoc_ary = false) + { + if (!is_array($assoc_ary)) + { + return false; + } + + $fields = array(); + $values = array(); + if ($query == 'INSERT') + { + foreach ($assoc_ary as $key => $var) + { + $fields[] = $key; + + if (is_null($var)) + { + $values[] = 'NULL'; + } + elseif (is_string($var)) + { + $values[] = "'" . $this->sql_escape($var) . "'"; + } + else + { + $values[] = (is_bool($var)) ? intval($var) : $var; + } + } + + $query = ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')'; + } + else if ($query == 'UPDATE') + { + $values = array(); + foreach ($assoc_ary as $key => $var) + { + if (is_null($var)) + { + $values[] = "$key = NULL"; + } + elseif (is_string($var)) + { + $values[] = "$key = '" . $this->sql_escape($var) . "'"; + } + else + { + $values[] = (is_bool($var)) ? "$key = " . intval($var) : "$key = $var"; + } + } + $query = implode(', ', $values); + } + + return $query; + } + + // Other query methods + function sql_numrows($query_id = false) + { + return 0; + } + + function sql_affectedrows() + { + return 0;// ?? + } + + function sql_fetchrow($query_id = 0) + { + global $cache; + + if (!$query_id) + { + $query_id = $this->query_result; + } + + if ($cache->sql_exists($query_id)) + { + return $cache->sql_fetchrow($query_id); + } + + return ($query_id) ? get_object_vars(@ibase_fetch_object($query_id)) : 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] = get_object_vars(@ibase_fetch_object($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][$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() + { + $query = "SELECT currval('" . $tablename[1] . "_id_seq') AS last_value"; + $temp_q_id = @ibase_query($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; + } + + function sql_freeresult($query_id = false) + { + if (!$query_id) + { + $query_id = $this->query_result; + } + + return ($query_id) ? @mysql_free_result($query_id) : false; + } + + function sql_escape($msg) + { + return (@ini_get('magic_quotes_sybase') || strtoupper(@ini_get('magic_quotes_sybase')) = 'ON') ? str_replace($replace_min('match'), $replace_min('replace'), $msg) : str_replace($replace_max('match'), $replace_max('replace'), $msg); + } + + function sql_error($sql = '') + { + if (!$this->return_on_error) + { + if ($this->transaction) + { + $this->sql_transaction('rollback'); + } + + $this_page = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; + $this_page .= '&' . ((!empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']); + + $message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @mysql_error() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . $this_page . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />'; + trigger_error($message, E_USER_ERROR); + } + + $result['message'] = @mysql_error(); + $result['code'] = @mysql_errno(); + + return $result; + } + +} // class sql_db + +} // if ... define + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/index.htm b/phpBB/includes/db/index.htm new file mode 100644 index 0000000000..ee1f723a7d --- /dev/null +++ b/phpBB/includes/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> diff --git a/phpBB/includes/db/msaccess.php b/phpBB/includes/db/msaccess.php new file mode 100644 index 0000000000..d3eff04c4c --- /dev/null +++ b/phpBB/includes/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$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/mssql-odbc.php b/phpBB/includes/db/mssql-odbc.php new file mode 100644 index 0000000000..e2b3e5cd91 --- /dev/null +++ b/phpBB/includes/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$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php new file mode 100644 index 0000000000..c54067f822 --- /dev/null +++ b/phpBB/includes/db/mssql.php @@ -0,0 +1,421 @@ +<?php +/*************************************************************************** + * mssql.php + * ------------------- + * begin : Saturday, Feb 13, 2001 + * copyright : (C) 2001 The phpBB Group + * email : supportphpbb.com + * + * $Id$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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( eregi("^INSERT ", $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] = stripslashes($value); + } + + 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] = stripslashes($value); + } + $i++; + } + + 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 = 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_escape($msg) + { + return str_replace("'", "''", str_replace('\\', '\\\\', $msg)); + } + + function sql_error($query_id = 0) + { + $result['message'] = @mssql_get_last_message(); + return $result; + } + +} // class sql_db + +} // if ... define + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php new file mode 100644 index 0000000000..868e5c109b --- /dev/null +++ b/phpBB/includes/db/mysql.php @@ -0,0 +1,445 @@ +<?php +/*************************************************************************** + * mysql.php + * ------------------- + * begin : Saturday, Feb 13, 2001 + * copyright : (C) 2001 The phpBB Group + * email : support@phpbb.com + * + * $Id$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 $return_on_error = false; + var $transaction = false; + var $sql_report = ''; + var $sql_time = 0; + + // + // Constructor + // + function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) + { + $this->open_queries = array(); + $this->num_queries = 0; + + $this->persistency = $persistency; + $this->user = $sqluser; + $this->password = $sqlpassword; + $this->server = $sqlserver . (($port) ? ':' . $port : ''); + $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 && $this->dbname != '') + { + if (@mysql_select_db($this->dbname)) + { + return $this->db_connect_id; + } + } + + $this->sql_error(''); + } + + // + // Other base methods + // + function sql_close() + { + if (!$this->db_connect_id) + { + return false; + } + + if (count($this->open_queries)) + { + foreach ($this->open_queries as $query_id) + { + @mysql_free_result($query_id); + } + } + + return @mysql_close($this->db_connect_id); + } + + function sql_return_on_error($fail = false) + { + $this->return_on_error = $fail; + } + + function sql_num_queries() + { + return $this->num_queries; + } + + function sql_transaction($status = 'begin') + { + switch ($status) + { + case 'begin': + $this->transaction = true; + $result = @mysql_query('BEGIN', $this->db_connect_id); + break; + + case 'commit': + $this->transaction = false; + $result = @mysql_query('COMMIT', $this->db_connect_id); + break; + + case 'rollback': + $this->transaction = false; + $result = @mysql_query('ROLLBACK', $this->db_connect_id); + break; + + default: + $result = true; + } + + return $result; + } + + // Base query method + function sql_query($query = '', $expire_time = 0) + { + if ($query != '') + { + global $cache; + + if (!$expire_time || !$cache->sql_load($query, $expire_time)) + { + if ($expire_time) + { + $cache_result = true; + } + + $this->query_result = false; + $this->num_queries++; + + if (!empty($_GET['explain'])) + { + global $starttime; + + $curtime = explode(' ', microtime()); + $curtime = $curtime[0] + $curtime[1] - $starttime; + } + + if (!$this->query_result = @mysql_query($query, $this->db_connect_id)) + { + $this->sql_error($query); + } + + if (!empty($_GET['explain'])) + { + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1] - $starttime; + + $this->sql_report .= "<pre>Query:\t" . htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n\t", $query)) . "\n\n"; + + if ($this->query_result) + { + $this->sql_report .= "Time before: $curtime\nTime after: $endtime\nElapsed time: <b>" . ($endtime - $curtime) . "</b>\n</pre>"; + } + else + { + $error = $this->sql_error(); + $this->sql_report .= '<b>FAILED</b> - MySQL Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']) . '<br><br><pre>'; + } + + $this->sql_time += $endtime - $curtime; + + if (preg_match('/^SELECT/', $query)) + { + $html_table = FALSE; + if ($result = mysql_query("EXPLAIN $query", $this->db_connect_id)) + { + while ($row = mysql_fetch_assoc($result)) + { + if (!$html_table && count($row)) + { + $html_table = TRUE; + $this->sql_report .= "<table width=100% border=1 cellpadding=2 cellspacing=1>\n"; + $this->sql_report .= "<tr>\n<td><b>" . implode("</b></td>\n<td><b>", array_keys($row)) . "</b></td>\n</tr>\n"; + } + $this->sql_report .= "<tr>\n<td>" . implode(" </td>\n<td>", array_values($row)) . " </td>\n</tr>\n"; + } + } + + if ($html_table) + { + $this->sql_report .= '</table><br>'; + } + } + + $this->sql_report .= "<hr>\n"; + } + + $this->open_queries[] = $this->query_result; + } + + if (!empty($cache_result)) + { + $cache->sql_save($query, $this->query_result); + @mysql_free_result(array_pop($this->open_queries)); + } + } + else + { + return false; + } + + return ($this->query_result) ? $this->query_result : false; + } + + // 20030406 Ashe: switched up $total and $offset as per MySQL manual + function sql_query_limit($query, $total, $offset = 0, $expire_time = 0) + { + if ($query != '') + { + $this->query_result = false; + $this->num_queries++; + + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) + { + $total = -1; + } + + $query .= ' LIMIT ' . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $expire_time); + } + else + { + return false; + } + } + + // Idea for this from Ikonboard + function sql_build_array($query, $assoc_ary = false) + { + if (!is_array($assoc_ary)) + { + return false; + } + + $fields = array(); + $values = array(); + if ($query == 'INSERT') + { + foreach ($assoc_ary as $key => $var) + { + $fields[] = $key; + + if (is_null($var)) + { + $values[] = 'NULL'; + } + elseif (is_string($var)) + { + $values[] = "'" . $this->sql_escape($var) . "'"; + } + else + { + $values[] = (is_bool($var)) ? intval($var) : $var; + } + } + + $query = ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')'; + } + else if ($query == 'UPDATE') + { + $values = array(); + foreach ($assoc_ary as $key => $var) + { + if (is_null($var)) + { + $values[] = "$key = NULL"; + } + elseif (is_string($var)) + { + $values[] = "$key = '" . $this->sql_escape($var) . "'"; + } + else + { + $values[] = (is_bool($var)) ? "$key = " . intval($var) : "$key = $var"; + } + } + $query = implode(', ', $values); + } + + return $query; + } + + // Other query methods + // + // NOTE :: Want to remove _ALL_ reliance on sql_numrows from core code ... + // don't want this here by a middle Milestone + function sql_numrows($query_id = false) + { + 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_fetchrow($query_id = 0) + { + global $cache; + + if (!$query_id) + { + $query_id = $this->query_result; + } + + if ($cache->sql_exists($query_id)) + { + return $cache->sql_fetchrow($query_id); + } + + return ($query_id) ? @mysql_fetch_assoc($query_id) : 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] = $this->sql_fetchrow($query_id)) + { + $result[] = $this->rowset[$query_id]; + } + return $result; + } + 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][$field]; + } + elseif ($this->row[$query_id]) + { + $result = $this->row[$query_id][$field]; + } + } + } + return $result; + } + 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 = false) + { + if (!$query_id) + { + $query_id = $this->query_result; + } + + return ($query_id) ? @mysql_free_result($query_id) : false; + } + + function sql_escape($msg) + { +// return str_replace("'", "''", str_replace('\\', '\\\\', $msg)); + return mysql_escape_string(stripslashes($msg)); + } + + function sql_error($sql = '') + { + $result = array( + 'message' => @mysql_error(), + 'code' => @mysql_errno() + ); + + if (!$this->return_on_error) + { + if ($this->transaction) + { + $this->sql_transaction('rollback'); + } + + $this_page = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; + $this_page .= '&' . ((!empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']); + + $message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @mysql_error() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . $this_page . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />'; + trigger_error($message, E_USER_ERROR); + } + + + return $result; + } + +} // class sql_db + +} // if ... define + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php new file mode 100644 index 0000000000..afd2bee28d --- /dev/null +++ b/phpBB/includes/db/mysql4.php @@ -0,0 +1,445 @@ +<?php +/*************************************************************************** + * mysql.php + * ------------------- + * begin : Saturday, Feb 13, 2001 + * copyright : (C) 2001 The phpBB Group + * email : support@phpbb.com + * + * $Id$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 $return_on_error = false; + var $transaction = false; + var $sql_report = ''; + var $sql_time = 0; + + // + // Constructor + // + function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $port, $persistency = false) + { + $this->open_queries = array(); + $this->num_queries = 0; + + $this->persistency = $persistency; + $this->user = $sqluser; + $this->password = $sqlpassword; + $this->server = $sqlserver . (($port) ? ':' . $port : ''); + $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 && $this->dbname != '') + { + if (@mysql_select_db($this->dbname)) + { + return $this->db_connect_id; + } + } + + $this->sql_error(''); + } + + // + // Other base methods + // + function sql_close() + { + if (!$this->db_connect_id) + { + return false; + } + + if (count($this->open_queries)) + { + foreach ($this->open_queries as $query_id) + { + @mysql_free_result($query_id); + } + } + + return @mysql_close($this->db_connect_id); + } + + function sql_return_on_error($fail = false) + { + $this->return_on_error = $fail; + } + + function sql_num_queries() + { + return $this->num_queries; + } + + function sql_transaction($status = 'begin') + { + switch ($status) + { + case 'begin': + $this->transaction = true; + $result = mysql_query('BEGIN', $this->db_connect_id); + break; + + case 'commit': + $this->transaction = false; + $result = mysql_query('COMMIT', $this->db_connect_id); + break; + + case 'rollback': + $this->transaction = false; + $result = mysql_query('ROLLBACK', $this->db_connect_id); + break; + + default: + $result = true; + } + + return $result; + } + + // + // Base query method + // + function sql_query($query = '', $expire_time = 0) + { + if ($query != '') + { + global $cache; + + if (!$expire_time || !$cache->sql_load($query, $expire_time)) + { + if ($expire_time) + { + $cache_result = true; + } + + $this->query_result = false; + $this->num_queries++; + + if (!empty($_GET['explain'])) + { + global $starttime; + + $curtime = explode(' ', microtime()); + $curtime = $curtime[0] + $curtime[1] - $starttime; + } + + if (!$this->query_result = @mysql_query($query, $this->db_connect_id)) + { + $this->sql_error($query); + } + + if (!empty($_GET['explain'])) + { + $endtime = explode(' ', microtime()); + $endtime = $endtime[0] + $endtime[1] - $starttime; + + $this->sql_report .= "<pre>Query:\t" . htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n\t", $query)) . "\n\n"; + + if ($this->query_result) + { + $this->sql_report .= "Time before: $curtime\nTime after: $endtime\nElapsed time: <b>" . ($endtime - $curtime) . "</b>\n</pre>"; + } + else + { + $error = $this->sql_error(); + $this->sql_report .= '<b>FAILED</b> - MySQL Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']) . '<br><br><pre>'; + } + + $this->sql_time += $endtime - $curtime; + + if (preg_match('/^SELECT/', $query)) + { + $html_table = FALSE; + if ($result = mysql_query("EXPLAIN $query", $this->db_connect_id)) + { + while ($row = mysql_fetch_assoc($result)) + { + if (!$html_table && count($row)) + { + $html_table = TRUE; + $this->sql_report .= "<table width=100% border=1 cellpadding=2 cellspacing=1>\n"; + $this->sql_report .= "<tr>\n<td><b>" . implode("</b></td>\n<td><b>", array_keys($row)) . "</b></td>\n</tr>\n"; + } + $this->sql_report .= "<tr>\n<td>" . implode(" </td>\n<td>", array_values($row)) . " </td>\n</tr>\n"; + } + } + + if ($html_table) + { + $this->sql_report .= '</table><br>'; + } + } + + $this->sql_report .= "<hr>\n"; + } + + $this->open_queries[] = $this->query_result; + } + + if (!empty($cache_result)) + { + $cache->sql_save($query, $this->query_result); + @mysql_free_result(array_pop($this->open_queries)); + } + } + else + { + return false; + } + + return ($this->query_result) ? $this->query_result : false; + } + + function sql_query_limit($query, $total, $offset = 0, $expire_time = 0) + { + if ($query != '') + { + $this->query_result = false; + $this->num_queries++; + + $query .= ' LIMIT ' . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $expire_time); + } + else + { + return false; + } + } + + // Idea for this from Ikonboard + function sql_build_array($query, $assoc_ary = false) + { + if (!is_array($assoc_ary)) + { + return false; + } + + $fields = array(); + $values = array(); + if ($query == 'INSERT') + { + foreach ($assoc_ary as $key => $var) + { + $fields[] = $key; + + if (is_null($var)) + { + $values[] = 'NULL'; + } + elseif (is_string($var)) + { + $values[] = "'" . $this->sql_escape($var) . "'"; + } + else + { + $values[] = (is_bool($var)) ? intval($var) : $var; + } + } + + $query = ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')'; + } + else if ($query == 'UPDATE') + { + $values = array(); + foreach ($assoc_ary as $key => $var) + { + if (is_null($var)) + { + $values[] = "$key = NULL"; + } + elseif (is_string($var)) + { + $values[] = "$key = '" . $this->sql_escape($var) . "'"; + } + else + { + $values[] = (is_bool($var)) ? "$key = " . intval($var) : "$key = $var"; + } + } + $query = implode(', ', $values); + } + + return $query; + } + + // + // Other query methods + // + // NOTE :: Want to remove _ALL_ reliance on sql_numrows from core code ... + // don't want this here by a middle Milestone + // + function sql_numrows($query_id = false) + { + 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_fetchrow($query_id = 0) + { + global $cache; + + if (!$query_id) + { + $query_id = $this->query_result; + } + + if ($cache->sql_exists($query_id)) + { + return $cache->sql_fetchrow($query_id); + } + + return ($query_id) ? @mysql_fetch_assoc($query_id) : 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_assoc($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][$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 = false) + { + if (!$query_id) + { + $query_id = $this->query_result; + } + + return ($query_id) ? @mysql_free_result($query_id) : false; + } + + function sql_escape($msg) + { +// return str_replace("'", "''", str_replace('\\', '\\\\', $msg)); + return mysql_escape_string(stripslashes($msg)); + } + + function sql_error($sql = '') + { + if (!$this->return_on_error) + { + if ($this->transaction) + { + $this->sql_transaction('rollback'); + } + + $this_page = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; + $this_page .= '&' . ((!empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']); + + $message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @mysql_error() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . $this_page . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />'; + trigger_error($message, E_USER_ERROR); + } + + $result['message'] = @mysql_error(); + $result['code'] = @mysql_errno(); + + return $result; + } + +} // class sql_db + +} // if ... define + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php new file mode 100644 index 0000000000..3319bca4ec --- /dev/null +++ b/phpBB/includes/db/oracle.php @@ -0,0 +1,472 @@ +<?php +/*************************************************************************** + * oracle.php + * ------------------- + * begin : Thrusday Feb 15, 2001 + * copyright : (C) 2001 The phpBB Group + * email : support@phpbb.com + * + * $Id$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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","oracle"); + +class sql_db +{ + + var $db_connect_id; + var $query_result; + var $in_transaction = 0; + var $row = array(); + var $rowset = array(); + var $num_queries = 0; + var $last_query_text = ""; + + // + // 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 = @OCIPLogon($this->user, $this->password, $this->server); + } + else + { + $this->db_connect_id = @OCINLogon($this->user, $this->password, $this->server); + } + if($this->db_connect_id) + { + return $this->db_connect_id; + } + else + { + return false; + } + } + + // + // Other base methods + // + function sql_close() + { + if($this->db_connect_id) + { + // Commit outstanding transactions + if($this->in_transaction) + { + OCICommit($this->db_connect_id); + } + + if($this->query_result) + { + @OCIFreeStatement($this->query_result); + } + $result = @OCILogoff($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); + + // Put us in transaction mode because with Oracle as soon as you make a query you're in a transaction + $this->in_transaction = TRUE; + + if($query != "") + { + $this->last_query = $query; + $this->num_queries++; + + 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]; + } + } + + if(eregi("^(INSERT|UPDATE) ", $query)) + { + $query = preg_replace("/\\\'/s", "''", $query); + } + + $this->query_result = @OCIParse($this->db_connect_id, $query); + $success = @OCIExecute($this->query_result, OCI_DEFAULT); + } + if($success) + { + if($transaction == END_TRANSACTION) + { + OCICommit($this->db_connect_id); + $this->in_transaction = FALSE; + } + + unset($this->row[$this->query_result]); + unset($this->rowset[$this->query_result]); + $this->last_query_text[$this->query_result] = $query; + + return $this->query_result; + } + else + { + if($this->in_transaction) + { + OCIRollback($this->db_connect_id); + } + return false; + } + } + + // + // Other query methods + // + function sql_numrows($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = @OCIFetchStatement($query_id, $this->rowset); + // OCIFetchStatment kills our query result so we have to execute the statment again + // if we ever want to use the query_id again. + @OCIExecute($query_id, OCI_DEFAULT); + return $result; + } + else + { + return false; + } + } + function sql_affectedrows($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = @OCIRowCount($query_id); + return $result; + } + else + { + return false; + } + } + function sql_numfields($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = @OCINumCols($query_id); + return $result; + } + else + { + return false; + } + } + function sql_fieldname($offset, $query_id = 0) + { + // OCIColumnName uses a 1 based array so we have to up the offset by 1 in here to maintain + // full abstraction compatibitly + $offset += 1; + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = strtolower(@OCIColumnName($query_id, $offset)); + return $result; + } + else + { + return false; + } + } + function sql_fieldtype($offset, $query_id = 0) + { + // This situation is the same as fieldname + $offset += 1; + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = @OCIColumnType($query_id, $offset); + return $result; + } + else + { + return false; + } + } + function sql_fetchrow($query_id = 0, $debug = FALSE) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result_row = ""; + $result = @OCIFetchInto($query_id, $result_row, OCI_ASSOC+OCI_RETURN_NULLS); + if($debug) + { + echo "Query was: ".$this->last_query . "<br>"; + echo "Result: $result<br>"; + echo "Query ID: $query_id<br>"; + echo "<pre>"; + var_dump($result_row); + echo "</pre>"; + } + if($result_row == "") + { + return false; + } + + for($i = 0; $i < count($result_row); $i++) + { + list($key, $val) = each($result_row); + $return_arr[strtolower($key)] = $val; + } + $this->row[$query_id] = $return_arr; + + return $this->row[$query_id]; + } + else + { + return false; + } + } + // This function probably isn't as efficant is it could be but any other way I do it + // I end up losing 1 row... + function sql_fetchrowset($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $rows = @OCIFetchStatement($query_id, $results); + @OCIExecute($query_id, OCI_DEFAULT); + for($i = 0; $i <= $rows; $i++) + { + @OCIFetchInto($query_id, $tmp_result, OCI_ASSOC+OCI_RETURN_NULLS); + + for($j = 0; $j < count($tmp_result); $j++) + { + list($key, $val) = each($tmp_result); + $return_arr[strtolower($key)] = $val; + } + $result[] = $return_arr; + } + 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) + { + // Reset the internal rownum pointer. + @OCIExecute($query_id, OCI_DEFAULT); + for($i = 0; $i < $rownum; $i++) + { + // Move the interal pointer to the row we want + @OCIFetch($query_id); + } + // Get the field data. + $result = @OCIResult($query_id, strtoupper($field)); + } + else + { + // The internal pointer should be where we want it + // so we just grab the field out of the current row. + $result = @OCIResult($query_id, strtoupper($field)); + } + return $result; + } + else + { + return false; + } + } + function sql_rowseek($rownum, $query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + @OCIExecute($query_id, OCI_DEFAULT); + for($i = 0; $i < $rownum; $i++) + { + @OCIFetch($query_id); + } + $result = @OCIFetch($query_id); + return $result; + } + else + { + return false; + } + } + function sql_nextid($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id && $this->last_query_text[$query_id] != "") + { + if( eregi("^(INSERT{1}|^INSERT INTO{1})[[:space:]][\"]?([a-zA-Z0-9\_\-]+)[\"]?", $this->last_query_text[$query_id], $tablename)) + { + $query = "SELECT ".$tablename[2]."_id_seq.currval FROM DUAL"; + $stmt = @OCIParse($this->db_connect_id, $query); + @OCIExecute($stmt,OCI_DEFAULT ); + $temp_result = @OCIFetchInto($stmt, $temp_result, OCI_ASSOC+OCI_RETURN_NULLS); + if($temp_result) + { + return $temp_result['CURRVAL']; + } + else + { + return false; + } + } + else + { + return false; + } + } + else + { + return false; + } + } + + function sql_nextid($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id && $this->last_query_text[$query_id] != "") + { + if( eregi("^(INSERT{1}|^INSERT INTO{1})[[:space:]][\"]?([a-zA-Z0-9\_\-]+)[\"]?", $this->last_query_text[$query_id], $tablename)) + { + $query = "SELECT ".$tablename[2]."_id_seq.CURRVAL FROM DUAL"; + $temp_q_id = @OCIParse($this->db_connect_id, $query); + @OCIExecute($temp_q_id, OCI_DEFAULT); + @OCIFetchInto($temp_q_id, $temp_result, OCI_ASSOC+OCI_RETURN_NULLS); + + if($temp_result) + { + return $temp_result['CURRVAL']; + } + else + { + return false; + } + } + else + { + return false; + } + } + else + { + return false; + } + } + + + + function sql_freeresult($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = @OCIFreeStatement($query_id); + return $result; + } + else + { + return false; + } + } + function sql_error($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + $result = @OCIError($query_id); + return $result; + } + +} // class sql_db + +} // if ... define + +?>
\ No newline at end of file diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php new file mode 100644 index 0000000000..96a90fbb1a --- /dev/null +++ b/phpBB/includes/db/postgres.php @@ -0,0 +1,397 @@ +<?php + /*************************************************************************** + * postgres7.php + * ------------------- + * begin : Saturday, Feb 13, 2001 + * copyright : (C) 2001 The phpBB Group + * email : supportphpbb.com + * + * $Id$ + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 + +?>
\ No newline at end of file |