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
663cb650
Commit
663cb650
authored
Apr 30, 2017
by
Piotr Różański
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better exception handling in mysqli connect
parent
fbed76eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
MysqliConnection.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
+5
-6
MysqliConnectionTest.php
...octrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php
+22
-0
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
View file @
663cb650
...
...
@@ -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 @
663cb650
...
...
@@ -28,11 +28,33 @@ class MysqliConnectionTest extends DbalTestCase
->
getMockForAbstractClass
();
}
protected
function
tearDown
()
{
if
(
$this
->
getName
()
==
"testRestoresErrorHandlerOnException"
)
{
restore_error_handler
();
}
}
public
function
testDoesNotRequireQueryForServerVersion
()
{
$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.'
);
}
/**
* @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