1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-09 02:06:32 +02:00

Updates of various types, sizes, colours and accessories ...

git-svn-id: file:///svn/phpbb/trunk@3531 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen
2003-02-25 18:20:33 +00:00
parent 02bcd7e2e1
commit 1aa274d1e7
5 changed files with 471 additions and 404 deletions

View File

@@ -19,7 +19,7 @@
*
***************************************************************************/
if ( !defined('SQL_LAYER') )
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'mysql4');
@@ -44,14 +44,14 @@ class sql_db
$this->persistency = $persistency;
$this->user = $sqluser;
$this->password = $sqlpassword;
$this->server = $sqlserver . ( ( $port ) ? ':' . $port : '' );
$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);
$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 ($this->db_connect_id && $this->dbname != '')
{
if ( @mysql_select_db($this->dbname) )
if (@mysql_select_db($this->dbname))
{
return $this->db_connect_id;
}
@@ -93,20 +93,23 @@ class sql_db
function sql_transaction($status = 'begin')
{
switch ( $status )
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;
}
@@ -117,88 +120,107 @@ class sql_db
//
// Base query method
//
function sql_query($query = '')
function sql_query($query = '', $expire_time = 0)
{
if ($query != '')
{
$this->query_result = false;
$this->num_queries++;
global $cache;
if (!empty($_REQUEST['explain']))
if (!$expire_time || !$cache->sql_load($query, $expire_time))
{
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($_REQUEST['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)
if ($expire_time)
{
$this->sql_report .= "Time before: $curtime\nTime after: $endtime\nElapsed time: <b>" . ($endtime - $curtime) . "</b>\n</pre>";
$cache_result = true;
}
else
$this->query_result = false;
$this->num_queries++;
if (!empty($_GET['explain']))
{
$error = $this->sql_error();
$this->sql_report .= '<b>FAILED</b> - MySQL Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']) . '<br><br><pre>';
global $starttime;
$curtime = explode(' ', microtime());
$curtime = $curtime[0] + $curtime[1] - $starttime;
}
$this->sql_time += $endtime - $curtime;
if (preg_match('/^SELECT/', $query))
if (!$this->query_result = @mysql_query($query, $this->db_connect_id))
{
$html_table = FALSE;
if ($result = mysql_query("EXPLAIN $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)
{
while ($row = mysql_fetch_assoc($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))
{
if (!$html_table && count($row))
while ($row = mysql_fetch_assoc($result))
{
$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";
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("&nbsp;</td>\n<td>", array_values($row)) . "&nbsp;</td>\n</tr>\n";
}
$this->sql_report .= "<tr>\n<td>" . implode("&nbsp;</td>\n<td>", array_values($row)) . "&nbsp;</td>\n</tr>\n";
}
if ($html_table)
{
$this->sql_report .= '</table><br>';
}
}
if ($html_table)
{
$this->sql_report .= '</table><br>';
}
$this->sql_report .= "<hr>\n";
}
$this->sql_report .= "<hr>\n";
$this->open_queries[] = $this->query_result;
}
$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;
return ($this->query_result) ? $this->query_result : false;
}
function sql_query_limit($query = '', $total, $offset = 0)
function sql_query_limit($query, $total, $offset = 0, $expire_time = 0)
{
if ( $query != '' )
if ($query != '')
{
$this->query_result = false;
$this->num_queries++;
if ( !empty($total) )
{
$query .= ' LIMIT ' . ( ( !empty($offset) ) ? $offset . ', ' . $total : $total );
}
$query .= ' LIMIT ' . ((!empty($offset)) ? $total . ', ' . $offset : $total);
return $this->sql_query($query);
return $this->sql_query($query, $expire_time);
}
else
{
@@ -270,27 +292,34 @@ class sql_db
//
function sql_numrows($query_id = false)
{
if ( !$query_id )
if (!$query_id)
{
$query_id = $this->query_result;
}
return ( $query_id ) ? @mysql_num_rows($query_id) : false;
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;
return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false;
}
function sql_fetchrow($query_id = 0)
{
if ( !$query_id )
global $cache;
if (!$query_id)
{
$query_id = $this->query_result;
}
return ( $query_id ) ? @mysql_fetch_assoc($query_id) : false;
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)
@@ -358,27 +387,27 @@ class sql_db
function sql_rowseek($rownum, $query_id = 0)
{
if ( !$query_id )
if (!$query_id)
{
$query_id = $this->query_result;
}
return ( $query_id ) ? @mysql_data_seek($query_id, $rownum) : false;
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;
return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false;
}
function sql_freeresult($query_id = false)
{
if ( !$query_id )
if (!$query_id)
{
$query_id = $this->query_result;
}
return ( $query_id ) ? @mysql_free_result($query_id) : false;
return ($query_id) ? @mysql_free_result($query_id) : false;
}
function sql_escape($msg)
@@ -389,17 +418,17 @@ class sql_db
function sql_error($sql = '')
{
if ( !$this->return_on_error )
if (!$this->return_on_error)
{
if ( $this->transaction )
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'] );
$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 />';
$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);
}