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
5fdedc4f
Commit
5fdedc4f
authored
Nov 15, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Connection#ping() to have clear behavior, refs GH-414
parent
8a18e986
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
15 deletions
+21
-15
Connection.php
lib/Doctrine/DBAL/Connection.php
+19
-8
ConnectionTest.php
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
+2
-7
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
5fdedc4f
...
...
@@ -1491,15 +1491,29 @@ class Connection implements DriverConnection
}
/**
* Ping the server!
* Ping the server
*
* When the server is not available the method returns FALSE.
* It is responsibility of the developer to handle this case
* and abort the request or reconnect manually:
*
* @example
*
* if ($conn->ping() === false) {
* $conn->close();
* $conn->connect();
* }
*
* It is undefined if the underlying driver attempts to reconnect
* or disconnect when the connection is not available anymore
* as long it returns TRUE when a reconnect succeeded and
* FALSE when the connection was dropped.
*
* @return bool
*/
public
function
ping
()
{
if
(
!
$this
->
_isConnected
)
{
return
false
;
// Don't connect if not done yet. It will be lazy on first use
}
$this
->
connect
();
if
(
$this
->
_conn
instanceof
PingableConnection
)
{
return
$this
->
_conn
->
ping
();
...
...
@@ -1510,10 +1524,7 @@ class Connection implements DriverConnection
return
true
;
}
catch
(
DBALException
$e
)
{
// As the underlying connection is unset, the next query will connect again thanks to the lazyness
$this
->
close
();
return
false
;
}
return
false
;
}
}
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
View file @
5fdedc4f
...
...
@@ -218,14 +218,9 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertEquals
(
$this
->
_conn
->
quote
(
"foo"
,
Type
::
STRING
),
$this
->
_conn
->
quote
(
"foo"
,
\PDO
::
PARAM_STR
));
}
public
function
testPingDoes
NotTrigger
Connect
()
public
function
testPingDoes
Triggers
Connect
()
{
$this
->
assertFalse
(
$this
->
_conn
->
ping
());
}
public
function
testPingReturnsTrueWhenConnectionIsPingedOrOpen
()
{
$this
->
_conn
->
connect
();
$this
->
assertTrue
(
$this
->
_conn
->
ping
());
$this
->
assertTrue
(
$this
->
_conn
->
isConnected
());
}
}
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