Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
c9ce80ac
Unverified
Commit
c9ce80ac
authored
Jun 15, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use error suppression instead of an error handler in MySQLi Connection
parent
a05f4493
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
35 deletions
+6
-35
MysqliConnection.php
src/Driver/Mysqli/MysqliConnection.php
+6
-12
MysqliConnectionTest.php
tests/Driver/Mysqli/MysqliConnectionTest.php
+0
-23
No files found.
src/Driver/Mysqli/MysqliConnection.php
View file @
c9ce80ac
...
...
@@ -17,8 +17,6 @@ use function mysqli_errno;
use
function
mysqli_error
;
use
function
mysqli_init
;
use
function
mysqli_options
;
use
function
restore_error_handler
;
use
function
set_error_handler
;
use
function
sprintf
;
use
function
stripos
;
...
...
@@ -70,16 +68,12 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
$this
->
setSecureConnection
(
$params
);
$this
->
setDriverOptions
(
$driverOptions
);
set_error_handler
(
static
function
()
:
bool
{
return
true
;
});
try
{
if
(
!
$this
->
conn
->
real_connect
(
$host
,
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
throw
new
MysqliException
(
$this
->
conn
->
connect_error
,
$this
->
conn
->
sqlstate
??
'HY000'
,
$this
->
conn
->
connect_errno
);
}
}
finally
{
restore_error_handler
();
if
(
!
@
$this
->
conn
->
real_connect
(
$host
,
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
throw
new
MysqliException
(
$this
->
conn
->
connect_error
,
$this
->
conn
->
sqlstate
??
'HY000'
,
$this
->
conn
->
connect_errno
);
}
if
(
!
isset
(
$params
[
'charset'
]))
{
...
...
tests/Driver/Mysqli/MysqliConnectionTest.php
View file @
c9ce80ac
...
...
@@ -4,14 +4,11 @@ namespace Doctrine\DBAL\Tests\Driver\Mysqli;
use
Doctrine\DBAL\Driver\Mysqli\HostRequired
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliConnection
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Tests\FunctionalTestCase
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
function
extension_loaded
;
use
function
restore_error_handler
;
use
function
set_error_handler
;
class
MysqliConnectionTest
extends
FunctionalTestCase
{
...
...
@@ -44,26 +41,6 @@ class MysqliConnectionTest extends FunctionalTestCase
self
::
assertFalse
(
$this
->
connectionMock
->
requiresQueryForServerVersion
());
}
public
function
testRestoresErrorHandlerOnException
()
:
void
{
$handler
=
static
function
()
:
bool
{
self
::
fail
(
'Never expected this to be called'
);
};
$defaultHandler
=
set_error_handler
(
$handler
);
try
{
new
MysqliConnection
([
'host'
=>
'255.255.255.255'
],
'user'
,
'pass'
);
self
::
fail
(
'An exception was supposed to be raised'
);
}
catch
(
MysqliException
$e
)
{
self
::
assertSame
(
'Network is unreachable'
,
$e
->
getMessage
());
}
self
::
assertSame
(
$handler
,
set_error_handler
(
$defaultHandler
),
'Restoring error handler failed.'
);
restore_error_handler
();
restore_error_handler
();
}
public
function
testHostnameIsRequiredForPersistentConnection
()
:
void
{
$this
->
expectException
(
HostRequired
::
class
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment