mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-05 23:25:30 +02:00
[ticket/17142] Fix DBMS+cache related PHP warnings while installing
PHPBB3-17142
This commit is contained in:
parent
75dcbeaa9f
commit
7adee3c50d
22
phpBB/phpbb/cache/driver/base.php
vendored
22
phpBB/phpbb/cache/driver/base.php
vendored
@ -115,6 +115,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
function sql_exists($query_id)
|
||||
{
|
||||
$query_id = $this->clean_query_id($query_id);
|
||||
return isset($this->sql_rowset[$query_id]);
|
||||
}
|
||||
|
||||
@ -123,6 +124,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
function sql_fetchrow($query_id)
|
||||
{
|
||||
$query_id = $this->clean_query_id($query_id);
|
||||
if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
|
||||
@ -136,6 +138,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
function sql_fetchfield($query_id, $field)
|
||||
{
|
||||
$query_id = $this->clean_query_id($query_id);
|
||||
if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false;
|
||||
@ -149,6 +152,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
function sql_rowseek($rownum, $query_id)
|
||||
{
|
||||
$query_id = $this->clean_query_id($query_id);
|
||||
if ($rownum >= count($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return false;
|
||||
@ -163,6 +167,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
function sql_freeresult($query_id)
|
||||
{
|
||||
$query_id = $this->clean_query_id($query_id);
|
||||
if (!isset($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return false;
|
||||
@ -231,4 +236,21 @@ abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
|
||||
@rmdir($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function clean_query_id($query_id)
|
||||
{
|
||||
// Some DBMS functions accept/return objects and/or resources instead of integer identifier
|
||||
// Attempting to cast object to int will throw error, hence correctly handle all cases
|
||||
if (is_resource($query_id))
|
||||
{
|
||||
return function_exists('get_resource_id') ? get_resource_id($query_id) : (int) $query_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return is_object($query_id) ? spl_object_id($query_id) : $query_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,4 +164,13 @@ interface driver_interface
|
||||
* @return bool
|
||||
*/
|
||||
public function sql_freeresult($query_id);
|
||||
|
||||
/**
|
||||
* Ensure query ID can be used by cache
|
||||
*
|
||||
* @param object|resource|int|string $query_id Mixed type query id
|
||||
*
|
||||
* @return int|string Query id in string or integer format
|
||||
*/
|
||||
public function clean_query_id($query_id);
|
||||
}
|
||||
|
@ -1245,4 +1245,25 @@ abstract class driver implements driver_interface
|
||||
|
||||
return $rows_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure query ID can be used by cache
|
||||
*
|
||||
* @param resource|int|string $query_id Mixed type query id
|
||||
*
|
||||
* @return int|string Query id in string or integer format
|
||||
*/
|
||||
public function clean_query_id($query_id)
|
||||
{
|
||||
// Some DBMS functions accept/return objects and/or resources instead if identifiers
|
||||
// Attempting to use objects/resources as array keys will throw error, hence correctly handle all cases
|
||||
if (is_resource($query_id))
|
||||
{
|
||||
return function_exists('get_resource_id') ? get_resource_id($query_id) : (int) $query_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return is_object($query_id) ? spl_object_id($query_id) : $query_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -494,4 +494,13 @@ interface driver_interface
|
||||
* @return string Quoted version of $msg
|
||||
*/
|
||||
public function sql_quote($msg);
|
||||
|
||||
/**
|
||||
* Ensure query ID can be used by cache
|
||||
*
|
||||
* @param resource|int|string $query_id Mixed type query id
|
||||
*
|
||||
* @return int|string Query id in string or integer format
|
||||
*/
|
||||
public function clean_query_id($query_id);
|
||||
}
|
||||
|
@ -185,14 +185,16 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
return false;
|
||||
}
|
||||
|
||||
$safe_query_id = $this->clean_query_id($this->query_result);
|
||||
|
||||
if ($cache && $cache_ttl)
|
||||
{
|
||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||
$this->open_queries[$safe_query_id] = $this->query_result;
|
||||
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||
}
|
||||
else if (strpos($query, 'SELECT') === 0)
|
||||
{
|
||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||
$this->open_queries[$safe_query_id] = $this->query_result;
|
||||
}
|
||||
}
|
||||
else if ($this->debug_sql_explain)
|
||||
@ -260,9 +262,10 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_fetchrow($query_id);
|
||||
return $cache->sql_fetchrow($safe_query_id);
|
||||
}
|
||||
|
||||
return ($query_id) ? odbc_fetch_array($query_id) : false;
|
||||
@ -301,14 +304,15 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
return $cache->sql_freeresult($safe_query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[(int) $query_id]))
|
||||
if (isset($this->open_queries[$safe_query_id]))
|
||||
{
|
||||
unset($this->open_queries[(int) $query_id]);
|
||||
unset($this->open_queries[$safe_query_id]);
|
||||
return odbc_free_result($query_id);
|
||||
}
|
||||
|
||||
|
@ -159,14 +159,16 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
return false;
|
||||
}
|
||||
|
||||
$safe_query_id = $this->clean_query_id($this->query_result);
|
||||
|
||||
if ($cache && $cache_ttl)
|
||||
{
|
||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||
$this->open_queries[$safe_query_id] = $this->query_result;
|
||||
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||
}
|
||||
else if (strpos($query, 'SELECT') === 0)
|
||||
{
|
||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||
$this->open_queries[$safe_query_id] = $this->query_result;
|
||||
}
|
||||
}
|
||||
else if ($this->debug_sql_explain)
|
||||
@ -242,9 +244,10 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_fetchrow($query_id);
|
||||
return $cache->sql_fetchrow($safe_query_id);
|
||||
}
|
||||
|
||||
if (!$query_id)
|
||||
@ -302,14 +305,15 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
return $cache->sql_freeresult($safe_query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[(int) $query_id]))
|
||||
if (isset($this->open_queries[$safe_query_id]))
|
||||
{
|
||||
unset($this->open_queries[(int) $query_id]);
|
||||
unset($this->open_queries[$safe_query_id]);
|
||||
return sqlsrv_free_stmt($query_id);
|
||||
}
|
||||
|
||||
|
@ -254,9 +254,10 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_fetchrow($query_id);
|
||||
return $cache->sql_fetchrow($safe_query_id);
|
||||
}
|
||||
|
||||
if ($query_id)
|
||||
@ -280,9 +281,10 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_rowseek($rownum, $query_id);
|
||||
return $cache->sql_rowseek($rownum, $safe_query_id);
|
||||
}
|
||||
|
||||
return ($query_id) ? @mysqli_data_seek($query_id, $rownum) : false;
|
||||
@ -308,9 +310,10 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
return $cache->sql_freeresult($safe_query_id);
|
||||
}
|
||||
|
||||
if (!$query_id)
|
||||
|
@ -441,14 +441,16 @@ class oracle extends \phpbb\db\driver\driver
|
||||
return false;
|
||||
}
|
||||
|
||||
$safe_query_id = $this->clean_query_id($this->query_result);
|
||||
|
||||
if ($cache && $cache_ttl)
|
||||
{
|
||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||
$this->open_queries[$safe_query_id] = $this->query_result;
|
||||
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||
}
|
||||
else if (strpos($query, 'SELECT') === 0)
|
||||
{
|
||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||
$this->open_queries[$safe_query_id] = $this->query_result;
|
||||
}
|
||||
}
|
||||
else if ($this->debug_sql_explain)
|
||||
@ -496,9 +498,10 @@ class oracle extends \phpbb\db\driver\driver
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_fetchrow($query_id);
|
||||
return $cache->sql_fetchrow($safe_query_id);
|
||||
}
|
||||
|
||||
if ($query_id)
|
||||
@ -544,9 +547,10 @@ class oracle extends \phpbb\db\driver\driver
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_rowseek($rownum, $query_id);
|
||||
return $cache->sql_rowseek($rownum, $safe_query_id);
|
||||
}
|
||||
|
||||
if (!$query_id)
|
||||
@ -619,14 +623,15 @@ class oracle extends \phpbb\db\driver\driver
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
return $cache->sql_freeresult($safe_query_id);
|
||||
}
|
||||
|
||||
if (isset($this->open_queries[(int) $query_id]))
|
||||
if (isset($this->open_queries[$safe_query_id]))
|
||||
{
|
||||
unset($this->open_queries[(int) $query_id]);
|
||||
unset($this->open_queries[$safe_query_id]);
|
||||
return oci_free_statement($query_id);
|
||||
}
|
||||
|
||||
|
@ -547,25 +547,4 @@ class postgres extends \phpbb\db\driver\driver
|
||||
{
|
||||
return '"' . $msg . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure query ID can be used by cache
|
||||
*
|
||||
* @param resource|int|string $query_id Mixed type query id
|
||||
*
|
||||
* @return int|string Query id in string or integer format
|
||||
*/
|
||||
private function clean_query_id($query_id)
|
||||
{
|
||||
// As of PHP 8.1 PgSQL functions accept/return \PgSQL\* objects instead of "pgsql *" resources
|
||||
// Attempting to cast object to int will throw error, hence correctly handle all cases
|
||||
if (is_resource($query_id))
|
||||
{
|
||||
return function_exists('get_resource_id') ? get_resource_id($query_id) : (int) $query_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return is_object($query_id) ? spl_object_id($query_id) : $query_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -233,9 +233,10 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_fetchrow($query_id);
|
||||
return $cache->sql_fetchrow($safe_query_id);
|
||||
}
|
||||
|
||||
return is_object($query_id) ? @$query_id->fetchArray(SQLITE3_ASSOC) : false;
|
||||
@ -261,9 +262,10 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
||||
$safe_query_id = $this->clean_query_id($query_id);
|
||||
if ($cache && $cache->sql_exists($safe_query_id))
|
||||
{
|
||||
return $cache->sql_freeresult($query_id);
|
||||
return $cache->sql_freeresult($safe_query_id);
|
||||
}
|
||||
|
||||
if ($query_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user