diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 87ab7eb181..c9183d1cdc 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -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); diff --git a/libraries/ErrorHandler.php b/libraries/ErrorHandler.php index 5fc72198dd..54f73ee4de 100644 --- a/libraries/ErrorHandler.php +++ b/libraries/ErrorHandler.php @@ -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 * diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 6f1584f026..f2f8a160dc 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -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, diff --git a/test/classes/ErrorHandlerTest.php b/test/classes/ErrorHandlerTest.php index 4e31ce9f2a..53b3e85dbc 100644 --- a/test/classes/ErrorHandlerTest.php +++ b/test/classes/ErrorHandlerTest.php @@ -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() + ); } /**