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
c5d298c5
Unverified
Commit
c5d298c5
authored
Apr 13, 2019
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented support for persistent connections in PDO and mysqli drivers
parent
de7b33d0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
1 deletion
+53
-1
MysqliConnection.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
+6
-1
Driver.php
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
+5
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
+5
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
+4
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
+5
-0
ConnectionTest.php
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
+28
-0
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
View file @
c5d298c5
...
...
@@ -56,6 +56,11 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
$socket
=
$params
[
'unix_socket'
]
??
ini_get
(
'mysqli.default_socket'
);
$dbname
=
$params
[
'dbname'
]
??
''
;
$host
=
$params
[
'host'
];
if
(
!
empty
(
$params
[
'persistent'
]))
{
$host
=
'p:'
.
$host
;
}
$flags
=
$driverOptions
[
static
::
OPTION_FLAGS
]
??
0
;
...
...
@@ -67,7 +72,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
set_error_handler
(
static
function
()
{
});
try
{
if
(
!
$this
->
conn
->
real_connect
(
$
params
[
'host'
]
,
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
if
(
!
$this
->
conn
->
real_connect
(
$
host
,
$username
,
$password
,
$dbname
,
$port
,
$socket
,
$flags
))
{
throw
MysqliException
::
fromConnectionError
(
$this
->
conn
);
}
}
finally
{
...
...
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
View file @
c5d298c5
...
...
@@ -8,6 +8,7 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Driver\AbstractMySQLDriver
;
use
Doctrine\DBAL\Driver\PDOConnection
;
use
Doctrine\DBAL\Driver\PDOException
;
use
PDO
;
/**
* PDO MySql driver.
...
...
@@ -19,6 +20,10 @@ class Driver extends AbstractMySQLDriver
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
{
if
(
!
empty
(
$params
[
'persistent'
]))
{
$driverOptions
[
PDO
::
ATTR_PERSISTENT
]
=
true
;
}
try
{
$conn
=
new
PDOConnection
(
$this
->
constructPdoDsn
(
$params
),
...
...
lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
View file @
c5d298c5
...
...
@@ -8,6 +8,7 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Driver\AbstractOracleDriver
;
use
Doctrine\DBAL\Driver\PDOConnection
;
use
Doctrine\DBAL\Driver\PDOException
;
use
PDO
;
/**
* PDO Oracle driver.
...
...
@@ -24,6 +25,10 @@ class Driver extends AbstractOracleDriver
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
{
if
(
!
empty
(
$params
[
'persistent'
]))
{
$driverOptions
[
PDO
::
ATTR_PERSISTENT
]
=
true
;
}
try
{
return
new
PDOConnection
(
$this
->
constructPdoDsn
(
$params
),
...
...
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
View file @
c5d298c5
...
...
@@ -21,6 +21,10 @@ class Driver extends AbstractPostgreSQLDriver
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
{
if
(
!
empty
(
$params
[
'persistent'
]))
{
$driverOptions
[
PDO
::
ATTR_PERSISTENT
]
=
true
;
}
try
{
$connection
=
new
PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
...
...
lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
View file @
c5d298c5
...
...
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace
Doctrine\DBAL\Driver\PDOSqlsrv
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
PDO
;
use
function
is_int
;
use
function
sprintf
;
...
...
@@ -28,6 +29,10 @@ class Driver extends AbstractSQLServerDriver
}
}
if
(
!
empty
(
$params
[
'persistent'
]))
{
$pdoOptions
[
PDO
::
ATTR_PERSISTENT
]
=
true
;
}
return
new
Connection
(
$this
->
_constructPdoDsn
(
$params
,
$dsnOptions
),
$username
,
...
...
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
View file @
c5d298c5
...
...
@@ -7,9 +7,13 @@ namespace Doctrine\Tests\DBAL\Functional;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\ConnectionException
;
use
Doctrine\DBAL\Driver\Connection
as
DriverConnection
;
use
Doctrine\DBAL\Driver\PDOConnection
;
use
Doctrine\DBAL\DriverManager
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\SqlitePlatform
;
use
Doctrine\DBAL\Platforms\SQLServerPlatform
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
use
Doctrine\Tests\TestUtil
;
use
Error
;
use
Exception
;
use
PDO
;
...
...
@@ -360,4 +364,28 @@ class ConnectionTest extends DbalFunctionalTestCase
])
->
ping
()
);
}
public
function
testPersistentConnection
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
||
$platform
instanceof
SQLServerPlatform
)
{
self
::
markTestSkipped
(
'The platform does not support persistent connections'
);
}
$params
=
TestUtil
::
getConnectionParams
();
$params
[
'persistent'
]
=
true
;
$connection
=
DriverManager
::
getConnection
(
$params
);
$driverConnection
=
$connection
->
getWrappedConnection
();
if
(
!
$driverConnection
instanceof
PDOConnection
)
{
self
::
markTestSkipped
(
'Unable to test if the connection is persistent'
);
}
$pdo
=
$driverConnection
->
getWrappedConnection
();
self
::
assertTrue
(
$pdo
->
getAttribute
(
PDO
::
ATTR_PERSISTENT
));
}
}
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