mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/10057] Fixed wrong usage of sql_error in postgres dbal.
pg_last_error does not work if no connection was ever established. Therefore we must keep track of connection errors in postgres dbal ourselves. PHPBB3-10057
This commit is contained in:
parent
edc1deaa3a
commit
98388b2921
1 changed files with 15 additions and 3 deletions
|
@ -31,6 +31,7 @@ if (!class_exists('phpbb_error_collector'))
|
||||||
class dbal_postgres extends dbal
|
class dbal_postgres extends dbal
|
||||||
{
|
{
|
||||||
var $last_query_text = '';
|
var $last_query_text = '';
|
||||||
|
var $connect_error = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to server
|
* Connect to server
|
||||||
|
@ -121,8 +122,8 @@ class dbal_postgres extends dbal
|
||||||
return $this->db_connect_id;
|
return $this->db_connect_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = $collector->format_errors();
|
$this->connect_error = $collector->format_errors();
|
||||||
return $this->sql_error($errors);
|
return $this->sql_error('');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -391,8 +392,19 @@ class dbal_postgres extends dbal
|
||||||
*/
|
*/
|
||||||
function _sql_error()
|
function _sql_error()
|
||||||
{
|
{
|
||||||
|
// pg_last_error only works when there is an established connection.
|
||||||
|
// Connection errors have to be tracked by us manually.
|
||||||
|
if ($this->db_connect_id)
|
||||||
|
{
|
||||||
|
$message = @pg_last_error($this->db_connect_id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$message = $this->connect_error;
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id),
|
'message' => $message,
|
||||||
'code' => ''
|
'code' => ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue