mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge pull request #6574 from rxu/ticket/17232-master
[ticket/17232] Improve SQL error messages handling - master version
This commit is contained in:
commit
9f099a75cd
5 changed files with 63 additions and 17 deletions
|
@ -161,7 +161,16 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
|
||||||
|
|
||||||
if ($this->query_result === false)
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false)
|
try
|
||||||
|
{
|
||||||
|
$this->query_result = @odbc_exec($this->db_connect_id, $query);
|
||||||
|
}
|
||||||
|
catch (\Error $e)
|
||||||
|
{
|
||||||
|
// Do nothing as SQL driver will report the error
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
$this->sql_error($query);
|
$this->sql_error($query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,12 +136,22 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
|
||||||
|
|
||||||
if ($this->query_result === false)
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
if (($this->query_result = @sqlsrv_query($this->db_connect_id, $query, array(), $this->query_options)) === false)
|
try
|
||||||
|
{
|
||||||
|
$this->query_result = @sqlsrv_query($this->db_connect_id, $query, array(), $this->query_options);
|
||||||
|
}
|
||||||
|
catch (\Error $e)
|
||||||
|
{
|
||||||
|
// Do nothing as SQL driver will report the error
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
$this->sql_error($query);
|
$this->sql_error($query);
|
||||||
}
|
}
|
||||||
// reset options for next query
|
|
||||||
$this->query_options = array();
|
// Reset options for the next query
|
||||||
|
$this->query_options = [];
|
||||||
|
|
||||||
if ($this->debug_sql_explain)
|
if ($this->debug_sql_explain)
|
||||||
{
|
{
|
||||||
|
|
|
@ -193,7 +193,16 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||||
|
|
||||||
if ($this->query_result === false)
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
|
try
|
||||||
|
{
|
||||||
|
$this->query_result = @mysqli_query($this->db_connect_id, $query);
|
||||||
|
}
|
||||||
|
catch (\Error $e)
|
||||||
|
{
|
||||||
|
// Do nothing as SQL driver will report the error
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
$this->sql_error($query);
|
$this->sql_error($query);
|
||||||
}
|
}
|
||||||
|
@ -332,24 +341,24 @@ class mysqli extends \phpbb\db\driver\mysql_base
|
||||||
{
|
{
|
||||||
if ($this->db_connect_id)
|
if ($this->db_connect_id)
|
||||||
{
|
{
|
||||||
$error = array(
|
$error = [
|
||||||
'message' => @mysqli_error($this->db_connect_id),
|
'message' => $this->db_connect_id->error,
|
||||||
'code' => @mysqli_errno($this->db_connect_id)
|
'code' => $this->db_connect_id->errno,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
else if (function_exists('mysqli_connect_error'))
|
else if (function_exists('mysqli_connect_error'))
|
||||||
{
|
{
|
||||||
$error = array(
|
$error = [
|
||||||
'message' => @mysqli_connect_error(),
|
'message' => $this->db_connect_id->connect_error,
|
||||||
'code' => @mysqli_connect_errno(),
|
'code' => $this->db_connect_id->connect_errno,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$error = array(
|
$error = [
|
||||||
'message' => $this->connect_error,
|
'message' => $this->connect_error,
|
||||||
'code' => '',
|
'code' => '',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error;
|
return $error;
|
||||||
|
|
|
@ -183,7 +183,16 @@ class postgres extends \phpbb\db\driver\driver
|
||||||
|
|
||||||
if ($this->query_result === false)
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false)
|
try
|
||||||
|
{
|
||||||
|
$this->query_result = @pg_query($this->db_connect_id, $query);
|
||||||
|
}
|
||||||
|
catch (\Error $e)
|
||||||
|
{
|
||||||
|
// Do nothing as SQL driver will report the error
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
$this->sql_error($query);
|
$this->sql_error($query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,16 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||||
$query = preg_replace('/^INSERT INTO/', 'INSERT OR ROLLBACK INTO', $query);
|
$query = preg_replace('/^INSERT INTO/', 'INSERT OR ROLLBACK INTO', $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($this->query_result = @$this->dbo->query($query)) === false)
|
try
|
||||||
|
{
|
||||||
|
$this->query_result = @$this->dbo->query($query);
|
||||||
|
}
|
||||||
|
catch (\Error $e)
|
||||||
|
{
|
||||||
|
// Do nothing as SQL driver will report the error
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->query_result === false)
|
||||||
{
|
{
|
||||||
// Try to recover a lost database connection
|
// Try to recover a lost database connection
|
||||||
if ($this->dbo && !@$this->dbo->lastErrorMsg())
|
if ($this->dbo && !@$this->dbo->lastErrorMsg())
|
||||||
|
|
Loading…
Add table
Reference in a new issue