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
0061022d
Commit
0061022d
authored
May 02, 2017
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/#2704-better-mysqli-exception-handling'
Close #2704
parents
fbed76eb
3ae969f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
MysqliConnection.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
+5
-6
MysqliConnectionTest.php
...octrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php
+17
-0
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
View file @
0061022d
...
...
@@ -67,15 +67,14 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
$this
->
setDriverOptions
(
$driverOptions
);
set_error_handler
(
function
()
{});
if
(
!
$this
->
_conn
->
real_connect
(
$params
[
'host'
],
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
try
{
if
(
!
$this
->
_conn
->
real_connect
(
$params
[
'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
();
throw
new
MysqliException
(
$this
->
_conn
->
connect_error
,
@
$this
->
_conn
->
sqlstate
?:
'HY000'
,
$this
->
_conn
->
connect_errno
);
}
restore_error_handler
();
if
(
isset
(
$params
[
'charset'
]))
{
$this
->
_conn
->
set_charset
(
$params
[
'charset'
]);
}
...
...
tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php
View file @
0061022d
...
...
@@ -33,6 +33,23 @@ class MysqliConnectionTest extends DbalTestCase
$this
->
assertFalse
(
$this
->
connectionMock
->
requiresQueryForServerVersion
());
}
public
function
testRestoresErrorHandlerOnException
()
{
$handler
=
function
()
{
self
::
fail
(
'Never expected this to be called'
);
};
$default_handler
=
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
(
$default_handler
),
'Restoring error handler failed.'
);
restore_error_handler
();
restore_error_handler
();
}
/**
* @dataProvider secureMissingParamsProvider
*/
...
...
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