mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
various fixes and alterations
git-svn-id: file:///svn/phpbb/trunk@4118 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
68f6998a4c
commit
dee0f40fd2
7 changed files with 298 additions and 207 deletions
|
@ -33,8 +33,7 @@ class sql_db
|
||||||
var $sql_report = '';
|
var $sql_report = '';
|
||||||
var $sql_time = 0;
|
var $sql_time = 0;
|
||||||
|
|
||||||
// Constructor
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database = '', $port = '', $persistency = false)
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database = '', $port = '', $persistency = false)
|
|
||||||
{
|
{
|
||||||
$this->open_queries = array();
|
$this->open_queries = array();
|
||||||
$this->num_queries = 0;
|
$this->num_queries = 0;
|
||||||
|
@ -44,7 +43,7 @@ class sql_db
|
||||||
$this->password = $sqlpassword;
|
$this->password = $sqlpassword;
|
||||||
$this->server = $sqlserver;
|
$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('');
|
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,7 @@ class sql_db
|
||||||
|
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
|
|
||||||
//
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
||||||
// Constructor
|
|
||||||
//
|
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
|
||||||
{
|
{
|
||||||
$this->persistency = $persistency;
|
$this->persistency = $persistency;
|
||||||
$this->server = $sqlserver;
|
$this->server = $sqlserver;
|
||||||
|
@ -52,10 +49,21 @@ class sql_db
|
||||||
$this->password = $sqlpassword;
|
$this->password = $sqlpassword;
|
||||||
$this->dbname = $database;
|
$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
|
// Other base methods
|
||||||
//
|
//
|
||||||
|
@ -63,12 +71,12 @@ class sql_db
|
||||||
{
|
{
|
||||||
if($this->db_connect_id)
|
if($this->db_connect_id)
|
||||||
{
|
{
|
||||||
if( $this->in_transaction )
|
if($this->in_transaction)
|
||||||
{
|
{
|
||||||
@odbc_commit($this->db_connect_id);
|
@odbc_commit($this->db_connect_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( count($this->result_rowset) )
|
if(count($this->result_rowset))
|
||||||
{
|
{
|
||||||
unset($this->result_rowset);
|
unset($this->result_rowset);
|
||||||
unset($this->field_names);
|
unset($this->field_names);
|
||||||
|
@ -90,13 +98,13 @@ class sql_db
|
||||||
//
|
//
|
||||||
function sql_query($query = "", $transaction = FALSE)
|
function sql_query($query = "", $transaction = FALSE)
|
||||||
{
|
{
|
||||||
if( $query != "" )
|
if($query != "")
|
||||||
{
|
{
|
||||||
$this->num_queries++;
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -105,23 +113,23 @@ class sql_db
|
||||||
|
|
||||||
$query = str_replace("LOWER(", "LCASE(", $query);
|
$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];
|
$query = $limits[1];
|
||||||
|
|
||||||
if( !empty($limits[2]) )
|
if(!empty($limits[2]))
|
||||||
{
|
{
|
||||||
$row_offset = ( $limits[4] ) ? $limits[3] : "";
|
$row_offset = ($limits[4]) ? $limits[3] : "";
|
||||||
$num_rows = ( $limits[4] ) ? $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");
|
$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++)
|
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->current_row[$this->result] = 0;
|
||||||
$this->result_rowset[$this->result] = array();
|
$this->result_rowset[$this->result] = array();
|
||||||
|
|
||||||
$row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1;
|
$row_outer = (isset($row_offset)) ? $row_offset + 1 : 1;
|
||||||
$row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9;
|
$row_outer_max = (isset($num_rows)) ? $row_offset + $num_rows + 1 : 1E9;
|
||||||
$row_inner = 0;
|
$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++)
|
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);
|
$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");
|
$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->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
|
||||||
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
|
$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);
|
$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);
|
$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_rollback($this->db_connect_id);
|
||||||
odbc_autocommit($this->db_connect_id, true);
|
odbc_autocommit($this->db_connect_id, true);
|
||||||
|
@ -193,11 +201,11 @@ class sql_db
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $transaction == END_TRANSACTION && $this->in_transaction )
|
if($transaction == END_TRANSACTION && $this->in_transaction)
|
||||||
{
|
{
|
||||||
$this->in_transaction = FALSE;
|
$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_rollback($this->db_connect_id);
|
||||||
odbc_autocommit($this->db_connect_id, true);
|
odbc_autocommit($this->db_connect_id, true);
|
||||||
|
@ -210,11 +218,11 @@ class sql_db
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( $transaction == END_TRANSACTION && $this->in_transaction )
|
if($transaction == END_TRANSACTION && $this->in_transaction)
|
||||||
{
|
{
|
||||||
$this->in_transaction = FALSE;
|
$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_rollback($this->db_connect_id);
|
||||||
odbc_autocommit($this->db_connect_id, true);
|
odbc_autocommit($this->db_connect_id, true);
|
||||||
|
@ -232,54 +240,54 @@ class sql_db
|
||||||
//
|
//
|
||||||
function sql_numrows($query_id = 0)
|
function sql_numrows($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_numfields($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fieldname($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fieldtype($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fetchrow($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -289,14 +297,14 @@ class sql_db
|
||||||
|
|
||||||
function sql_fetchrowset($query_id = 0)
|
function sql_fetchrowset($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -306,14 +314,14 @@ class sql_db
|
||||||
|
|
||||||
function sql_fetchfield($field, $row = -1, $query_id = 0)
|
function sql_fetchfield($field, $row = -1, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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;
|
||||||
|
|
||||||
|
@ -332,12 +340,12 @@ class sql_db
|
||||||
|
|
||||||
function sql_rowseek($offset, $query_id = 0)
|
function sql_rowseek($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$query_id = $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $query_id )
|
if($query_id)
|
||||||
{
|
{
|
||||||
$this->current_row[$query_id] = $offset - 1;
|
$this->current_row[$query_id] = $offset - 1;
|
||||||
return true;
|
return true;
|
||||||
|
@ -350,17 +358,17 @@ class sql_db
|
||||||
|
|
||||||
function sql_nextid()
|
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()
|
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)
|
function sql_freeresult($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$query_id = $this->result;
|
||||||
}
|
}
|
||||||
|
@ -374,12 +382,28 @@ class sql_db
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sql_error()
|
function sql_error($sql = '')
|
||||||
{
|
{
|
||||||
$error['code'] = "";//odbc_error($this->db_connect_id);
|
if (!$this->return_on_error)
|
||||||
$error['message'] = "Error";//odbc_errormsg($this->db_connect_id);
|
{
|
||||||
|
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 = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @odbc_errormsg() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . htmlspecialchars($this_page) . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />';
|
||||||
|
trigger_error($message, E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'message' => @odbc_errormsg(),
|
||||||
|
'code' => @odbc_error()
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // class sql_db
|
} // class sql_db
|
||||||
|
|
|
@ -40,10 +40,7 @@ class sql_db
|
||||||
|
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
|
|
||||||
//
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
||||||
// Constructor
|
|
||||||
//
|
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
|
||||||
{
|
{
|
||||||
$this->persistency = $persistency;
|
$this->persistency = $persistency;
|
||||||
$this->server = $sqlserver;
|
$this->server = $sqlserver;
|
||||||
|
@ -51,10 +48,21 @@ class sql_db
|
||||||
$this->password = $sqlpassword;
|
$this->password = $sqlpassword;
|
||||||
$this->dbname = $database;
|
$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
|
// Other base methods
|
||||||
//
|
//
|
||||||
|
@ -62,12 +70,12 @@ class sql_db
|
||||||
{
|
{
|
||||||
if($this->db_connect_id)
|
if($this->db_connect_id)
|
||||||
{
|
{
|
||||||
if( $this->in_transaction )
|
if($this->in_transaction)
|
||||||
{
|
{
|
||||||
@odbc_commit($this->db_connect_id);
|
@odbc_commit($this->db_connect_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( count($this->result_rowset) )
|
if(count($this->result_rowset))
|
||||||
{
|
{
|
||||||
unset($this->result_rowset);
|
unset($this->result_rowset);
|
||||||
unset($this->field_names);
|
unset($this->field_names);
|
||||||
|
@ -89,36 +97,36 @@ class sql_db
|
||||||
//
|
//
|
||||||
function sql_query($query = "", $transaction = FALSE)
|
function sql_query($query = "", $transaction = FALSE)
|
||||||
{
|
{
|
||||||
if( $query != "" )
|
if($query != "")
|
||||||
{
|
{
|
||||||
$this->num_queries++;
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
$this->in_transaction = TRUE;
|
$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];
|
$query = $limits[1];
|
||||||
|
|
||||||
if( !empty($limits[2]) )
|
if(!empty($limits[2]))
|
||||||
{
|
{
|
||||||
$row_offset = ( $limits[4] ) ? $limits[3] : "";
|
$row_offset = ($limits[4]) ? $limits[3] : "";
|
||||||
$num_rows = ( $limits[4] ) ? $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");
|
$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++)
|
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->current_row[$this->result] = 0;
|
||||||
$this->result_rowset[$this->result] = array();
|
$this->result_rowset[$this->result] = array();
|
||||||
|
|
||||||
$row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1;
|
$row_outer = (isset($row_offset)) ? $row_offset + 1 : 1;
|
||||||
$row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9;
|
$row_outer_max = (isset($num_rows)) ? $row_offset + $num_rows + 1 : 1E9;
|
||||||
$row_inner = 0;
|
$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++)
|
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);
|
$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");
|
$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->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
|
||||||
$this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
|
$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);
|
$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);
|
$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_rollback($this->db_connect_id);
|
||||||
odbc_autocommit($this->db_connect_id, true);
|
odbc_autocommit($this->db_connect_id, true);
|
||||||
|
@ -188,11 +196,11 @@ class sql_db
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $transaction == END_TRANSACTION && $this->in_transaction )
|
if($transaction == END_TRANSACTION && $this->in_transaction)
|
||||||
{
|
{
|
||||||
$this->in_transaction = FALSE;
|
$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_rollback($this->db_connect_id);
|
||||||
odbc_autocommit($this->db_connect_id, true);
|
odbc_autocommit($this->db_connect_id, true);
|
||||||
|
@ -207,11 +215,11 @@ class sql_db
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( $transaction == END_TRANSACTION && $this->in_transaction )
|
if($transaction == END_TRANSACTION && $this->in_transaction)
|
||||||
{
|
{
|
||||||
$this->in_transaction = FALSE;
|
$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_rollback($this->db_connect_id);
|
||||||
odbc_autocommit($this->db_connect_id, true);
|
odbc_autocommit($this->db_connect_id, true);
|
||||||
|
@ -229,54 +237,54 @@ class sql_db
|
||||||
//
|
//
|
||||||
function sql_numrows($query_id = 0)
|
function sql_numrows($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_numfields($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fieldname($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fieldtype($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fetchrow($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -286,14 +294,14 @@ class sql_db
|
||||||
|
|
||||||
function sql_fetchrowset($query_id = 0)
|
function sql_fetchrowset($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -303,16 +311,16 @@ class sql_db
|
||||||
|
|
||||||
function sql_fetchfield($field, $row = -1, $query_id = 0)
|
function sql_fetchfield($field, $row = -1, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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]];
|
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)
|
function sql_rowseek($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$query_id = $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $query_id )
|
if($query_id)
|
||||||
{
|
{
|
||||||
$this->current_row[$query_id] = $offset - 1;
|
$this->current_row[$query_id] = $offset - 1;
|
||||||
return true;
|
return true;
|
||||||
|
@ -348,17 +356,17 @@ class sql_db
|
||||||
|
|
||||||
function sql_nextid()
|
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()
|
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)
|
function sql_freeresult($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$query_id = $this->result;
|
||||||
}
|
}
|
||||||
|
@ -372,12 +380,28 @@ class sql_db
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sql_error()
|
function sql_error($sql = '')
|
||||||
{
|
{
|
||||||
$error['code'] = odbc_error($this->db_connect_id);
|
if (!$this->return_on_error)
|
||||||
$error['message'] = odbc_errormsg($this->db_connect_id);
|
{
|
||||||
|
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 = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @odbc_errormsg() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . htmlspecialchars($this_page) . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />';
|
||||||
|
trigger_error($message, E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'message' => @odbc_errormsg(),
|
||||||
|
'code' => @odbc_error()
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // class sql_db
|
} // class sql_db
|
||||||
|
|
|
@ -40,10 +40,7 @@ class sql_db
|
||||||
|
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
|
|
||||||
//
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
||||||
// Constructor
|
|
||||||
//
|
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
|
||||||
{
|
{
|
||||||
$this->persistency = $persistency;
|
$this->persistency = $persistency;
|
||||||
$this->user = $sqluser;
|
$this->user = $sqluser;
|
||||||
|
@ -51,18 +48,28 @@ class sql_db
|
||||||
$this->server = $sqlserver;
|
$this->server = $sqlserver;
|
||||||
$this->dbname = $database;
|
$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 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
|
// Commit any remaining transactions
|
||||||
//
|
//
|
||||||
if( $this->in_transaction )
|
if($this->in_transaction)
|
||||||
{
|
{
|
||||||
@mssql_query("COMMIT", $this->db_connect_id);
|
@mssql_query("COMMIT", $this->db_connect_id);
|
||||||
}
|
}
|
||||||
|
@ -100,13 +107,13 @@ class sql_db
|
||||||
unset($this->result);
|
unset($this->result);
|
||||||
unset($this->row);
|
unset($this->row);
|
||||||
|
|
||||||
if ( $query != "" )
|
if ($query != "")
|
||||||
{
|
{
|
||||||
$this->num_queries++;
|
$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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -125,40 +132,40 @@ class sql_db
|
||||||
// returns something then there's a problem. This may well be a false assumption though
|
// returns something then there's a problem. This may well be a false assumption though
|
||||||
// ... needs checking under Windows itself.
|
// ... 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];
|
$query = $limits[1];
|
||||||
|
|
||||||
if( !empty($limits[2]) )
|
if(!empty($limits[2]))
|
||||||
{
|
{
|
||||||
$row_offset = ( $limits[4] ) ? $limits[3] : "";
|
$row_offset = ($limits[4]) ? $limits[3] : "";
|
||||||
$num_rows = ( $limits[4] ) ? $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);
|
$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);
|
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();
|
$this->result = time() + microtime();
|
||||||
|
|
||||||
$result_id = mssql_query("SELECT @@IDENTITY AS id, @@ROWCOUNT as affected", $this->db_connect_id);
|
$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->next_id[$this->db_connect_id] = $row['id'];
|
||||||
$this->affected_rows[$this->db_connect_id] = $row['affected'];
|
$this->affected_rows[$this->db_connect_id] = $row['affected'];
|
||||||
|
@ -168,14 +175,14 @@ class sql_db
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( mssql_query($query, $this->db_connect_id) )
|
if(mssql_query($query, $this->db_connect_id))
|
||||||
{
|
{
|
||||||
$this->result = time() + microtime();
|
$this->result = time() + microtime();
|
||||||
|
|
||||||
$result_id = mssql_query("SELECT @@ROWCOUNT as affected", $this->db_connect_id);
|
$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'];
|
$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);
|
mssql_query("ROLLBACK", $this->db_connect_id);
|
||||||
$this->in_transaction = FALSE;
|
$this->in_transaction = FALSE;
|
||||||
|
@ -194,11 +201,11 @@ class sql_db
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $transaction == END_TRANSACTION && $this->in_transaction )
|
if($transaction == END_TRANSACTION && $this->in_transaction)
|
||||||
{
|
{
|
||||||
$this->in_transaction = FALSE;
|
$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);
|
@mssql_query("ROLLBACK", $this->db_connect_id);
|
||||||
return false;
|
return false;
|
||||||
|
@ -209,11 +216,11 @@ class sql_db
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( $transaction == END_TRANSACTION && $this->in_transaction )
|
if($transaction == END_TRANSACTION && $this->in_transaction )
|
||||||
{
|
{
|
||||||
$this->in_transaction = FALSE;
|
$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);
|
@mssql_query("ROLLBACK", $this->db_connect_id);
|
||||||
return false;
|
return false;
|
||||||
|
@ -229,14 +236,14 @@ class sql_db
|
||||||
//
|
//
|
||||||
function sql_numrows($query_id = 0)
|
function sql_numrows($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -246,22 +253,22 @@ class sql_db
|
||||||
|
|
||||||
function sql_numfields($query_id = 0)
|
function sql_numfields($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fieldname($offset, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fieldtype($offset, $query_id = 0)
|
||||||
|
@ -271,23 +278,23 @@ class sql_db
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_fetchrow($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$query_id = $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $query_id )
|
if($query_id)
|
||||||
{
|
{
|
||||||
empty($row);
|
empty($row);
|
||||||
|
|
||||||
$row = mssql_fetch_array($query_id);
|
$row = mssql_fetch_array($query_id);
|
||||||
|
|
||||||
while( list($key, $value) = @each($row) )
|
while(list($key, $value) = @each($row))
|
||||||
{
|
{
|
||||||
$row[$key] = stripslashes($value);
|
$row[$key] = stripslashes($value);
|
||||||
}
|
}
|
||||||
|
@ -302,19 +309,19 @@ class sql_db
|
||||||
|
|
||||||
function sql_fetchrowset($query_id = 0)
|
function sql_fetchrowset($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$query_id = $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $query_id )
|
if($query_id)
|
||||||
{
|
{
|
||||||
$i = 0;
|
$i = 0;
|
||||||
empty($rowset);
|
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);
|
$rowset[$i][$key] = stripslashes($value);
|
||||||
}
|
}
|
||||||
|
@ -331,18 +338,18 @@ class sql_db
|
||||||
|
|
||||||
function sql_fetchfield($field, $row = -1, $query_id)
|
function sql_fetchfield($field, $row = -1, $query_id)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -351,7 +358,7 @@ class sql_db
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( empty($this->row[$query_id]) )
|
if(empty($this->row[$query_id]))
|
||||||
{
|
{
|
||||||
$this->row[$query_id] = mssql_fetch_array($query_id);
|
$this->row[$query_id] = mssql_fetch_array($query_id);
|
||||||
$result = stripslashes($this->row[$query_id][$field]);
|
$result = stripslashes($this->row[$query_id][$field]);
|
||||||
|
@ -368,14 +375,14 @@ class sql_db
|
||||||
|
|
||||||
function sql_rowseek($rownum, $query_id = 0)
|
function sql_rowseek($rownum, $query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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
|
else
|
||||||
{
|
{
|
||||||
|
@ -385,22 +392,22 @@ class sql_db
|
||||||
|
|
||||||
function sql_nextid()
|
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()
|
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)
|
function sql_freeresult($query_id = 0)
|
||||||
{
|
{
|
||||||
if( !$query_id )
|
if(!$query_id)
|
||||||
{
|
{
|
||||||
$query_id = $this->result;
|
$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)
|
function sql_escape($msg)
|
||||||
|
@ -408,9 +415,27 @@ class sql_db
|
||||||
return str_replace("'", "''", str_replace('\\', '\\\\', $msg));
|
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 = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @mssql_get_last_message() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . htmlspecialchars($this_page) . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />';
|
||||||
|
trigger_error($message, E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'message' => @mssql_get_last_message(),
|
||||||
|
'code' => ''
|
||||||
|
);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,7 @@ class sql_db
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
var $open_queries = array();
|
var $open_queries = array();
|
||||||
|
|
||||||
//
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
|
||||||
// Constructor
|
|
||||||
//
|
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
|
|
||||||
{
|
{
|
||||||
$this->persistency = $persistency;
|
$this->persistency = $persistency;
|
||||||
$this->user = $sqluser;
|
$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 = '')
|
function sql_error($sql = '')
|
||||||
{
|
{
|
||||||
$result = array(
|
|
||||||
'message' => @mysql_error(),
|
|
||||||
'code' => @mysql_errno()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$this->return_on_error)
|
if (!$this->return_on_error)
|
||||||
{
|
{
|
||||||
if ($this->transaction)
|
if ($this->transaction)
|
||||||
|
@ -434,6 +426,10 @@ class sql_db
|
||||||
trigger_error($message, E_USER_ERROR);
|
trigger_error($message, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'message' => @mysql_error(),
|
||||||
|
'code' => @mysql_errno()
|
||||||
|
);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,7 @@ class sql_db
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
var $open_queries = array();
|
var $open_queries = array();
|
||||||
|
|
||||||
// Constructor
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port, $persistency = false)
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $port, $persistency = false)
|
|
||||||
{
|
{
|
||||||
$this->persistency = $persistency;
|
$this->persistency = $persistency;
|
||||||
$this->user = $sqluser;
|
$this->user = $sqluser;
|
||||||
|
@ -54,7 +53,7 @@ class sql_db
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->sql_error('');
|
return $this->sql_error('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other base methods
|
// Other base methods
|
||||||
|
@ -424,8 +423,10 @@ class sql_db
|
||||||
trigger_error($message, E_USER_ERROR);
|
trigger_error($message, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['message'] = @mysql_error();
|
$result = array(
|
||||||
$result['code'] = @mysql_errno();
|
'message' => @mysql_error(),
|
||||||
|
'code' => @mysql_errno()
|
||||||
|
);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class sql_db
|
||||||
//
|
//
|
||||||
// Constructor
|
// Constructor
|
||||||
//
|
//
|
||||||
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
|
||||||
{
|
{
|
||||||
$this->connect_string = "";
|
$this->connect_string = "";
|
||||||
|
|
||||||
|
@ -76,9 +76,19 @@ class sql_db
|
||||||
|
|
||||||
$this->persistency = $persistency;
|
$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;
|
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 = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @pg_errormessage() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . htmlspecialchars($this_page) . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />';
|
||||||
|
trigger_error($message, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['message'] = @pg_errormessage($this->db_connect_id);
|
$result = array(
|
||||||
$result['code'] = -1;
|
'message' => @pg_errormessage(),
|
||||||
|
'code' => ''
|
||||||
|
);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue