diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php
index 0c29ae36cb..247f3dd429 100644
--- a/phpBB/includes/db/firebird.php
+++ b/phpBB/includes/db/firebird.php
@@ -33,8 +33,7 @@ class sql_db
var $sql_report = '';
var $sql_time = 0;
- // Constructor
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database = '', $port = '', $persistency = false)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database = '', $port = '', $persistency = false)
{
$this->open_queries = array();
$this->num_queries = 0;
@@ -44,7 +43,7 @@ class sql_db
$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);
+ $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('');
}
diff --git a/phpBB/includes/db/msaccess.php b/phpBB/includes/db/msaccess.php
index d3eff04c4c..3e38cff7b0 100644
--- a/phpBB/includes/db/msaccess.php
+++ b/phpBB/includes/db/msaccess.php
@@ -41,10 +41,7 @@ class sql_db
var $num_queries = 0;
- //
- // Constructor
- //
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->server = $sqlserver;
@@ -52,10 +49,21 @@ class sql_db
$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);
+ $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;
+ return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
+
+ function sql_return_on_error($fail = false)
+ {
+ $this->return_on_error = $fail;
+ }
+
+ function sql_num_queries()
+ {
+ return $this->num_queries;
+ }
+
//
// Other base methods
//
@@ -63,12 +71,12 @@ class sql_db
{
if($this->db_connect_id)
{
- if( $this->in_transaction )
+ if($this->in_transaction)
{
@odbc_commit($this->db_connect_id);
}
- if( count($this->result_rowset) )
+ if(count($this->result_rowset))
{
unset($this->result_rowset);
unset($this->field_names);
@@ -90,13 +98,13 @@ class sql_db
//
function sql_query($query = "", $transaction = FALSE)
{
- if( $query != "" )
+ if($query != "")
{
$this->num_queries++;
- if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
+ if($transaction == BEGIN_TRANSACTION && !$this->in_transaction)
{
- if( !odbc_autocommit($this->db_connect_id, false) )
+ if(!odbc_autocommit($this->db_connect_id, false))
{
return false;
}
@@ -105,23 +113,23 @@ class sql_db
$query = str_replace("LOWER(", "LCASE(", $query);
- if( preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits) )
+ if(preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits))
{
$query = $limits[1];
- if( !empty($limits[2]) )
+ if(!empty($limits[2]))
{
- $row_offset = ( $limits[4] ) ? $limits[3] : "";
- $num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
+ $row_offset = ($limits[4]) ? $limits[3] : "";
+ $num_rows = ($limits[4]) ? $limits[4] : $limits[3];
- $query = "TOP " . ( $row_offset + $num_rows ) . $query;
+ $query = "TOP " . ($row_offset + $num_rows) . $query;
}
$this->result = odbc_exec($this->db_connect_id, "SELECT $query");
- if( $this->result )
+ if($this->result)
{
- if( empty($this->field_names[$this->result]) )
+ if(empty($this->field_names[$this->result]))
{
for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++)
{
@@ -133,11 +141,11 @@ class sql_db
$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_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 )
+ while(odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max)
{
for($j = 0; $j < count($this->field_names[$this->result]); $j++)
{
@@ -154,16 +162,16 @@ class sql_db
}
}
- else if( eregi("^INSERT ", $query) )
+ else if(eregi("^INSERT ", $query))
{
$this->result = odbc_exec($this->db_connect_id, $query);
- if( $this->result )
+ if($this->result)
{
$result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
- if( $result_id )
+ if($result_id)
{
- if( odbc_fetch_row($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);
@@ -175,15 +183,15 @@ class sql_db
{
$this->result = odbc_exec($this->db_connect_id, $query);
- if( $this->result )
+ if($this->result)
{
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
- if( !$this->result )
+ if(!$this->result)
{
- if( $this->in_transaction )
+ if($this->in_transaction)
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -193,11 +201,11 @@ class sql_db
return false;
}
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
- if ( !@odbc_commit($this->db_connect_id) )
+ if (!@odbc_commit($this->db_connect_id))
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -210,11 +218,11 @@ class sql_db
}
else
{
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
- if ( !@odbc_commit($this->db_connect_id) )
+ if (!@odbc_commit($this->db_connect_id))
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -232,54 +240,54 @@ class sql_db
//
function sql_numrows($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? $this->num_rows[$query_id] : false;
+ return ($query_id) ? $this->num_rows[$query_id] : false;
}
function sql_numfields($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? count($this->field_names[$query_id]) : false;
+ return ($query_id) ? count($this->field_names[$query_id]) : false;
}
function sql_fieldname($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? $this->field_names[$query_id][$offset] : false;
+ return ($query_id) ? $this->field_names[$query_id][$offset] : false;
}
function sql_fieldtype($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? $this->field_types[$query_id][$offset] : false;
+ return ($query_id) ? $this->field_types[$query_id][$offset] : false;
}
function sql_fetchrow($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ 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;
+ 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
{
@@ -289,14 +297,14 @@ class sql_db
function sql_fetchrowset($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
- return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false;
+ return ($this->num_rows[$query_id]) ? $this->result_rowset[$query_id] : false;
}
else
{
@@ -306,14 +314,14 @@ class sql_db
function sql_fetchfield($field, $row = -1, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
- if( $row < $this->num_rows[$query_id] )
+ if($row < $this->num_rows[$query_id])
{
$getrow = ($row == -1) ? $this->current_row[$query_id] - 1 : $row;
@@ -332,12 +340,12 @@ class sql_db
function sql_rowseek($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
$this->current_row[$query_id] = $offset - 1;
return true;
@@ -350,17 +358,17 @@ class sql_db
function sql_nextid()
{
- return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
+ 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;
+ 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 )
+ if(!$query_id)
{
$query_id = $this->result;
}
@@ -374,12 +382,28 @@ class sql_db
return true;
}
- function sql_error()
+ function sql_error($sql = '')
{
- $error['code'] = "";//odbc_error($this->db_connect_id);
- $error['message'] = "Error";//odbc_errormsg($this->db_connect_id);
+ if (!$this->return_on_error)
+ {
+ if ($this->transaction)
+ {
+ $this->sql_transaction('rollback');
+ }
- return $error;
+ $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 = 'SQL ERROR [ ' . SQL_LAYER . ' ]
' . @odbc_errormsg() . '
CALLING PAGE
' . htmlspecialchars($this_page) . (($sql != '') ? '
SQL
' . $sql : '') . '
';
+ trigger_error($message, E_USER_ERROR);
+ }
+
+ $result = array(
+ 'message' => @odbc_errormsg(),
+ 'code' => @odbc_error()
+ );
+
+ return $result;
}
} // class sql_db
diff --git a/phpBB/includes/db/mssql-odbc.php b/phpBB/includes/db/mssql-odbc.php
index e2b3e5cd91..09834d414e 100644
--- a/phpBB/includes/db/mssql-odbc.php
+++ b/phpBB/includes/db/mssql-odbc.php
@@ -40,10 +40,7 @@ class sql_db
var $num_queries = 0;
- //
- // Constructor
- //
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->server = $sqlserver;
@@ -51,10 +48,21 @@ class sql_db
$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);
+ $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;
+ return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
+
+ function sql_return_on_error($fail = false)
+ {
+ $this->return_on_error = $fail;
+ }
+
+ function sql_num_queries()
+ {
+ return $this->num_queries;
+ }
+
//
// Other base methods
//
@@ -62,12 +70,12 @@ class sql_db
{
if($this->db_connect_id)
{
- if( $this->in_transaction )
+ if($this->in_transaction)
{
@odbc_commit($this->db_connect_id);
}
- if( count($this->result_rowset) )
+ if(count($this->result_rowset))
{
unset($this->result_rowset);
unset($this->field_names);
@@ -89,36 +97,36 @@ class sql_db
//
function sql_query($query = "", $transaction = FALSE)
{
- if( $query != "" )
+ if($query != "")
{
$this->num_queries++;
- if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
+ if($transaction == BEGIN_TRANSACTION && !$this->in_transaction)
{
- if( !odbc_autocommit($this->db_connect_id, false) )
+ 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) )
+ if(preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits))
{
$query = $limits[1];
- if( !empty($limits[2]) )
+ if(!empty($limits[2]))
{
- $row_offset = ( $limits[4] ) ? $limits[3] : "";
- $num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
+ $row_offset = ($limits[4]) ? $limits[3] : "";
+ $num_rows = ($limits[4]) ? $limits[4] : $limits[3];
- $query = "TOP " . ( $row_offset + $num_rows ) . $query;
+ $query = "TOP " . ($row_offset + $num_rows) . $query;
}
$this->result = odbc_exec($this->db_connect_id, "SELECT $query");
- if( $this->result )
+ if($this->result)
{
- if( empty($this->field_names[$this->result]) )
+ if(empty($this->field_names[$this->result]))
{
for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++)
{
@@ -130,11 +138,11 @@ class sql_db
$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_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 )
+ while(odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max)
{
for($j = 0; $j < count($this->field_names[$this->result]); $j++)
{
@@ -149,16 +157,16 @@ class sql_db
}
}
- else if( eregi("^INSERT ", $query) )
+ else if(eregi("^INSERT ", $query))
{
$this->result = odbc_exec($this->db_connect_id, $query);
- if( $this->result )
+ if($this->result)
{
$result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
- if( $result_id )
+ if($result_id)
{
- if( odbc_fetch_row($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);
@@ -170,15 +178,15 @@ class sql_db
{
$this->result = odbc_exec($this->db_connect_id, $query);
- if( $this->result )
+ if($this->result)
{
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
}
}
- if( !$this->result )
+ if(!$this->result)
{
- if( $this->in_transaction )
+ if($this->in_transaction)
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -188,11 +196,11 @@ class sql_db
return false;
}
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
- if ( !odbc_commit($this->db_connect_id) )
+ if (!odbc_commit($this->db_connect_id))
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -207,11 +215,11 @@ class sql_db
}
else
{
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
- if ( !@odbc_commit($this->db_connect_id) )
+ if (!@odbc_commit($this->db_connect_id))
{
odbc_rollback($this->db_connect_id);
odbc_autocommit($this->db_connect_id, true);
@@ -229,54 +237,54 @@ class sql_db
//
function sql_numrows($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? $this->num_rows[$query_id] : false;
+ return ($query_id) ? $this->num_rows[$query_id] : false;
}
function sql_numfields($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? count($this->field_names[$query_id]) : false;
+ return ($query_id) ? count($this->field_names[$query_id]) : false;
}
function sql_fieldname($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? $this->field_names[$query_id][$offset] : false;
+ return ($query_id) ? $this->field_names[$query_id][$offset] : false;
}
function sql_fieldtype($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? $this->field_types[$query_id][$offset] : false;
+ return ($query_id) ? $this->field_types[$query_id][$offset] : false;
}
function sql_fetchrow($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ 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;
+ 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
{
@@ -286,14 +294,14 @@ class sql_db
function sql_fetchrowset($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
- return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false;
+ return ($this->num_rows[$query_id]) ? $this->result_rowset[$query_id] : false;
}
else
{
@@ -303,16 +311,16 @@ class sql_db
function sql_fetchfield($field, $row = -1, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
- if( $row < $this->num_rows[$query_id] )
+ if($row < $this->num_rows[$query_id])
{
- $getrow = ( $row == -1 ) ? $this->current_row[$query_id] - 1 : $row;
+ $getrow = ($row == -1) ? $this->current_row[$query_id] - 1 : $row;
return $this->result_rowset[$query_id][$getrow][$this->field_names[$query_id][$field]];
@@ -330,12 +338,12 @@ class sql_db
function sql_rowseek($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
$this->current_row[$query_id] = $offset - 1;
return true;
@@ -348,17 +356,17 @@ class sql_db
function sql_nextid()
{
- return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
+ 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;
+ 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 )
+ if(!$query_id)
{
$query_id = $this->result;
}
@@ -372,12 +380,28 @@ class sql_db
return true;
}
- function sql_error()
+ function sql_error($sql = '')
{
- $error['code'] = odbc_error($this->db_connect_id);
- $error['message'] = odbc_errormsg($this->db_connect_id);
+ if (!$this->return_on_error)
+ {
+ if ($this->transaction)
+ {
+ $this->sql_transaction('rollback');
+ }
- return $error;
+ $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 = 'SQL ERROR [ ' . SQL_LAYER . ' ]
' . @odbc_errormsg() . '
CALLING PAGE
' . htmlspecialchars($this_page) . (($sql != '') ? '
SQL
' . $sql : '') . '
';
+ trigger_error($message, E_USER_ERROR);
+ }
+
+ $result = array(
+ 'message' => @odbc_errormsg(),
+ 'code' => @odbc_error()
+ );
+
+ return $result;
}
} // class sql_db
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index c54067f822..fc5b1b0c44 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -40,10 +40,7 @@ class sql_db
var $num_queries = 0;
- //
- // Constructor
- //
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->persistency = $persistency;
$this->user = $sqluser;
@@ -51,18 +48,28 @@ class sql_db
$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);
+ $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($this->db_connect_id && $this->dbname != '')
{
- if( !mssql_select_db($this->dbname, $this->db_connect_id) )
+ if(!@mssql_select_db($this->dbname, $this->db_connect_id))
{
- mssql_close($this->db_connect_id);
+ @mssql_close($this->db_connect_id);
return false;
}
}
- return $this->db_connect_id;
+ return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
+ }
+
+ function sql_return_on_error($fail = false)
+ {
+ $this->return_on_error = $fail;
+ }
+
+ function sql_num_queries()
+ {
+ return $this->num_queries;
}
//
@@ -75,7 +82,7 @@ class sql_db
//
// Commit any remaining transactions
//
- if( $this->in_transaction )
+ if($this->in_transaction)
{
@mssql_query("COMMIT", $this->db_connect_id);
}
@@ -100,13 +107,13 @@ class sql_db
unset($this->result);
unset($this->row);
- if ( $query != "" )
+ if ($query != "")
{
$this->num_queries++;
- if ( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
+ if ($transaction == BEGIN_TRANSACTION && !$this->in_transaction)
{
- if ( !mssql_query("BEGIN TRANSACTION", $this->db_connect_id) )
+ if (!mssql_query("BEGIN TRANSACTION", $this->db_connect_id))
{
return false;
}
@@ -125,40 +132,40 @@ class sql_db
// 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) )
+ if(preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits))
{
$query = $limits[1];
- if( !empty($limits[2]) )
+ if(!empty($limits[2]))
{
- $row_offset = ( $limits[4] ) ? $limits[3] : "";
- $num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
+ $row_offset = ($limits[4]) ? $limits[3] : "";
+ $num_rows = ($limits[4]) ? $limits[4] : $limits[3];
- $query = "TOP " . ( $row_offset + $num_rows ) . $query;
+ $query = "TOP " . ($row_offset + $num_rows) . $query;
}
$this->result = mssql_query("SELECT $query", $this->db_connect_id);
- if( $this->result )
+ if($this->result)
{
- $this->limit_offset[$this->result] = ( !empty($row_offset) ) ? $row_offset : 0;
+ $this->limit_offset[$this->result] = (!empty($row_offset)) ? $row_offset : 0;
- if( $row_offset > 0 )
+ if($row_offset > 0)
{
mssql_data_seek($this->result, $row_offset);
}
}
}
- else if( eregi("^INSERT ", $query) )
+ else if(eregi("^INSERT ", $query))
{
- if( mssql_query($query, $this->db_connect_id) )
+ 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($result_id)
{
- if( $row = mssql_fetch_array($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'];
@@ -168,14 +175,14 @@ class sql_db
}
else
{
- if( mssql_query($query, $this->db_connect_id) )
+ 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($result_id)
{
- if( $row = mssql_fetch_array($result_id) )
+ if($row = mssql_fetch_array($result_id))
{
$this->affected_rows[$this->db_connect_id] = $row['affected'];
}
@@ -183,9 +190,9 @@ class sql_db
}
}
- if( !$this->result )
+ if(!$this->result)
{
- if( $this->in_transaction )
+ if($this->in_transaction)
{
mssql_query("ROLLBACK", $this->db_connect_id);
$this->in_transaction = FALSE;
@@ -194,11 +201,11 @@ class sql_db
return false;
}
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if($transaction == END_TRANSACTION && $this->in_transaction)
{
$this->in_transaction = FALSE;
- if( !@mssql_query("COMMIT", $this->db_connect_id) )
+ if(!@mssql_query("COMMIT", $this->db_connect_id))
{
@mssql_query("ROLLBACK", $this->db_connect_id);
return false;
@@ -209,11 +216,11 @@ class sql_db
}
else
{
- if( $transaction == END_TRANSACTION && $this->in_transaction )
+ if($transaction == END_TRANSACTION && $this->in_transaction )
{
$this->in_transaction = FALSE;
- if( !@mssql_query("COMMIT", $this->db_connect_id) )
+ if(!@mssql_query("COMMIT", $this->db_connect_id))
{
@mssql_query("ROLLBACK", $this->db_connect_id);
return false;
@@ -229,14 +236,14 @@ class sql_db
//
function sql_numrows($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ 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);
+ return (!empty($this->limit_offset[$query_id])) ? mssql_num_rows($query_id) - $this->limit_offset[$query_id] : @mssql_num_rows($query_id);
}
else
{
@@ -246,22 +253,22 @@ class sql_db
function sql_numfields($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? mssql_num_fields($query_id) : false;
+ return ($query_id) ? mssql_num_fields($query_id) : false;
}
function sql_fieldname($offset, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? mssql_field_name($query_id, $offset) : false;
+ return ($query_id) ? mssql_field_name($query_id, $offset) : false;
}
function sql_fieldtype($offset, $query_id = 0)
@@ -271,23 +278,23 @@ class sql_db
$query_id = $this->result;
}
- return ( $query_id ) ? mssql_field_type($query_id, $offset) : false;
+ return ($query_id) ? mssql_field_type($query_id, $offset) : false;
}
function sql_fetchrow($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
empty($row);
$row = mssql_fetch_array($query_id);
- while( list($key, $value) = @each($row) )
+ while(list($key, $value) = @each($row))
{
$row[$key] = stripslashes($value);
}
@@ -302,19 +309,19 @@ class sql_db
function sql_fetchrowset($query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
$i = 0;
empty($rowset);
- while( $row = mssql_fetch_array($query_id))
+ while($row = mssql_fetch_array($query_id))
{
- while( list($key, $value) = @each($row) )
+ while(list($key, $value) = @each($row))
{
$rowset[$i][$key] = stripslashes($value);
}
@@ -331,18 +338,18 @@ class sql_db
function sql_fetchfield($field, $row = -1, $query_id)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ if($query_id)
{
- if( $row != -1 )
+ if($row != -1)
{
- if( $this->limit_offset[$query_id] > 0 )
+ 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;
+ $result = (!empty($this->limit_offset[$query_id])) ? mssql_result($this->result, ($this->limit_offset[$query_id] + $row), $field) : false;
}
else
{
@@ -351,7 +358,7 @@ class sql_db
}
else
{
- if( empty($this->row[$query_id]) )
+ if(empty($this->row[$query_id]))
{
$this->row[$query_id] = mssql_fetch_array($query_id);
$result = stripslashes($this->row[$query_id][$field]);
@@ -368,14 +375,14 @@ class sql_db
function sql_rowseek($rownum, $query_id = 0)
{
- if( !$query_id )
+ if(!$query_id)
{
$query_id = $this->result;
}
- if( $query_id )
+ 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);
+ 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
{
@@ -385,22 +392,22 @@ class sql_db
function sql_nextid()
{
- return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
+ 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;
+ 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 )
+ if(!$query_id)
{
$query_id = $this->result;
}
- return ( $query_id ) ? mssql_free_result($query_id) : false;
+ return ($query_id) ? mssql_free_result($query_id) : false;
}
function sql_escape($msg)
@@ -408,9 +415,27 @@ class sql_db
return str_replace("'", "''", str_replace('\\', '\\\\', $msg));
}
- function sql_error($query_id = 0)
+ function sql_error($sql = '')
{
- $result['message'] = @mssql_get_last_message();
+ 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 = 'SQL ERROR [ ' . SQL_LAYER . ' ]
' . @mssql_get_last_message() . '
CALLING PAGE
' . htmlspecialchars($this_page) . (($sql != '') ? '
SQL
' . $sql : '') . '
';
+ trigger_error($message, E_USER_ERROR);
+ }
+
+ $result = array(
+ 'message' => @mssql_get_last_message(),
+ 'code' => ''
+ );
+
return $result;
}
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 6346567076..ad12650af0 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -35,10 +35,7 @@ class sql_db
var $num_queries = 0;
var $open_queries = array();
- //
- // Constructor
- //
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
@@ -56,7 +53,7 @@ class sql_db
}
}
- $this->sql_error('');
+ return $this->sql_error('');
}
//
@@ -415,11 +412,6 @@ class sql_db
function sql_error($sql = '')
{
- $result = array(
- 'message' => @mysql_error(),
- 'code' => @mysql_errno()
- );
-
if (!$this->return_on_error)
{
if ($this->transaction)
@@ -434,6 +426,10 @@ class sql_db
trigger_error($message, E_USER_ERROR);
}
+ $result = array(
+ 'message' => @mysql_error(),
+ 'code' => @mysql_errno()
+ );
return $result;
}
diff --git a/phpBB/includes/db/mysql4.php b/phpBB/includes/db/mysql4.php
index 6eb0a2c811..d916239088 100644
--- a/phpBB/includes/db/mysql4.php
+++ b/phpBB/includes/db/mysql4.php
@@ -35,8 +35,7 @@ class sql_db
var $num_queries = 0;
var $open_queries = array();
- // Constructor
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $port, $persistency = false)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port, $persistency = false)
{
$this->persistency = $persistency;
$this->user = $sqluser;
@@ -54,7 +53,7 @@ class sql_db
}
}
- $this->sql_error('');
+ return $this->sql_error('');
}
// Other base methods
@@ -424,8 +423,10 @@ class sql_db
trigger_error($message, E_USER_ERROR);
}
- $result['message'] = @mysql_error();
- $result['code'] = @mysql_errno();
+ $result = array(
+ 'message' => @mysql_error(),
+ 'code' => @mysql_errno()
+ );
return $result;
}
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php
index 644fba48b0..8f916eae99 100644
--- a/phpBB/includes/db/postgres.php
+++ b/phpBB/includes/db/postgres.php
@@ -38,7 +38,7 @@ class sql_db
//
// Constructor
//
- function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->connect_string = "";
@@ -76,9 +76,19 @@ class sql_db
$this->persistency = $persistency;
- $this->db_connect_id = ($this->persistency) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string);
+ $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;
+ return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
+ }
+
+ function sql_return_on_error($fail = false)
+ {
+ $this->return_on_error = $fail;
+ }
+
+ function sql_num_queries()
+ {
+ return $this->num_queries;
}
//
@@ -351,15 +361,27 @@ class sql_db
return ($query_id) ? @pg_freeresult($query_id) : false;
}
- function sql_error($query_id = 0)
+ function sql_error($sql = '')
{
- if (!$query_id)
+
+ if (!$this->return_on_error)
{
- $query_id = $this->query_result;
+ 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 = 'SQL ERROR [ ' . SQL_LAYER . ' ]
' . @pg_errormessage() . '
CALLING PAGE
' . htmlspecialchars($this_page) . (($sql != '') ? '
SQL
' . $sql : '') . '
';
+ trigger_error($message, E_USER_ERROR);
}
- $result['message'] = @pg_errormessage($this->db_connect_id);
- $result['code'] = -1;
+ $result = array(
+ 'message' => @pg_errormessage(),
+ 'code' => ''
+ );
return $result;
}