Merge pull request #12193 from nijel/connect-error
Do not hide errors from database connection attempts
This commit is contained in:
commit
9e2ae0c6ac
@ -2351,10 +2351,22 @@ class DatabaseInterface
|
||||
$user, $password, $is_controluser = false, $server = null,
|
||||
$auxiliary_connection = false
|
||||
) {
|
||||
$error_count = $GLOBALS['error_handler']->countErrors();
|
||||
$result = $this->_extension->connect(
|
||||
$user, $password, $is_controluser, $server, $auxiliary_connection
|
||||
);
|
||||
|
||||
/* Any errors from connection? */
|
||||
if ($GLOBALS['error_handler']->countErrors() > $error_count) {
|
||||
$errors = $GLOBALS['error_handler']->sliceErrors($error_count);
|
||||
foreach ($errors as $error) {
|
||||
trigger_error(
|
||||
$error->getMessage(),
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
if (! $auxiliary_connection && ! $is_controluser) {
|
||||
$GLOBALS['dbi']->postConnect($result);
|
||||
|
||||
@ -82,7 +82,7 @@ class ErrorHandler
|
||||
*
|
||||
* @return Error[]
|
||||
*/
|
||||
protected function getErrors()
|
||||
public function getErrors()
|
||||
{
|
||||
$this->checkSavedErrors();
|
||||
return $this->errors;
|
||||
@ -99,6 +99,20 @@ class ErrorHandler
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops recent erros from the storage
|
||||
*
|
||||
* @param int $count Old error count
|
||||
*
|
||||
* @return Error[]
|
||||
*/
|
||||
public function sliceErrors($count)
|
||||
{
|
||||
$errors = $this->getErrors();
|
||||
$this->errors = array_splice($errors, 0, $count);
|
||||
return array_splice($errors, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler - called when errors are triggered/occurred
|
||||
*
|
||||
|
||||
@ -84,7 +84,7 @@ class DBIMysqli implements DBIExtension
|
||||
}
|
||||
|
||||
if ($client_flags === null) {
|
||||
return @mysqli_real_connect(
|
||||
return mysqli_real_connect(
|
||||
$link,
|
||||
$host,
|
||||
$user,
|
||||
@ -94,7 +94,7 @@ class DBIMysqli implements DBIExtension
|
||||
$server_socket
|
||||
);
|
||||
} else {
|
||||
return @mysqli_real_connect(
|
||||
return mysqli_real_connect(
|
||||
$link,
|
||||
$host,
|
||||
$user,
|
||||
|
||||
@ -184,14 +184,43 @@ class ErrorHandlerTest extends PMATestCase
|
||||
*/
|
||||
public function testCountErrors()
|
||||
{
|
||||
$this->object->addError(
|
||||
'Compile Error', E_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
}
|
||||
|
||||
$err = array();
|
||||
$err[] = new PMA\libraries\Error('256', 'Compile Error', 'error.txt', 15);
|
||||
$errHandler = $this->getMock('PMA\libraries\ErrorHandler');
|
||||
$errHandler->expects($this->any())
|
||||
->method('getErrors')
|
||||
->will($this->returnValue($err));
|
||||
|
||||
/**
|
||||
* Test for sliceErrors
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testSliceErrors()
|
||||
{
|
||||
$this->object->addError(
|
||||
'Compile Error', E_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$this->object->sliceErrors(1)
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countErrors()
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count($this->object->sliceErrors(0))
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->countErrors()
|
||||
@ -205,18 +234,20 @@ class ErrorHandlerTest extends PMATestCase
|
||||
*/
|
||||
public function testCountUserErrors()
|
||||
{
|
||||
|
||||
$err = array();
|
||||
$err[] = new PMA\libraries\Error('256', 'Compile Error', 'error.txt', 15);
|
||||
$errHandler = $this->getMock('PMA\libraries\ErrorHandler');
|
||||
$errHandler->expects($this->any())
|
||||
->method('countErrors', 'getErrors')
|
||||
->will($this->returnValue(1, $err));
|
||||
|
||||
$this->object->addError(
|
||||
'Compile Error', E_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->object->countUserErrors()
|
||||
);
|
||||
$this->object->addError(
|
||||
'Compile Error', E_USER_WARNING, 'error.txt', 15
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->object->countUserErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user