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
a57e05a9
Commit
a57e05a9
authored
Nov 08, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #394 from easybiblabs/topics/mysqli-driver-params
Enhancement: add support for $driverOptions
parents
d79ce18e
11a23e20
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
MysqliConnection.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
+48
-0
ConnectionTest.php
.../Doctrine/Tests/DBAL/Functional/Mysqli/ConnectionTest.php
+57
-0
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
View file @
a57e05a9
...
...
@@ -52,6 +52,8 @@ class MysqliConnection implements Connection
if
(
isset
(
$params
[
'charset'
]))
{
$this
->
_conn
->
set_charset
(
$params
[
'charset'
]);
}
$this
->
setDriverOptions
(
$driverOptions
);
}
/**
...
...
@@ -151,4 +153,50 @@ class MysqliConnection implements Connection
{
return
$this
->
_conn
->
error
;
}
/**
* Apply the driver options to the connection.
*
* @param array $driverOptions
*
* @throws MysqliException When one of of the options is not supported.
* @throws MysqliException When applying doesn't work - e.g. due to incorrect value.
*/
private
function
setDriverOptions
(
array
$driverOptions
=
array
())
{
$supportedDriverOptions
=
array
(
\MYSQLI_OPT_CONNECT_TIMEOUT
,
\MYSQLI_OPT_LOCAL_INFILE
,
\MYSQLI_INIT_COMMAND
,
\MYSQLI_READ_DEFAULT_FILE
,
\MYSQLI_READ_DEFAULT_GROUP
,
);
if
(
version_compare
(
PHP_VERSION
,
'5.5.0'
)
>=
0
)
{
$supportedDriverOptions
[]
=
\MYSQLI_SERVER_PUBLIC_KEY
;
}
$exceptionMsg
=
"%s option '%s' with value '%s'"
;
foreach
(
$driverOptions
as
$option
=>
$value
)
{
if
(
!
in_array
(
$option
,
$supportedDriverOptions
,
true
))
{
throw
new
MysqliException
(
sprintf
(
$exceptionMsg
,
'Unsupported'
,
$option
,
$value
)
);
}
if
(
@
mysqli_options
(
$this
->
_conn
,
$option
,
$value
))
{
continue
;
}
$msg
=
sprintf
(
$exceptionMsg
,
'Failed to set'
,
$option
,
$value
);
$msg
.=
sprintf
(
', error: %s (%d)'
,
mysqli_error
(
$this
->
_conn
),
mysqli_errno
(
$this
->
_conn
));
throw
new
MysqliException
(
$msg
,
mysqli_errno
(
$this
->
_conn
)
);
}
}
}
tests/Doctrine/Tests/DBAL/Functional/Mysqli/ConnectionTest.php
0 → 100644
View file @
a57e05a9
<?php
namespace
Doctrine\Tests\DBAL\Functional\Mysqli
;
class
ConnectionTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
setUp
()
{
if
(
!
extension_loaded
(
'mysqli'
))
{
$this
->
markTestSkipped
(
'mysqli is not installed.'
);
}
$driver
=
getenv
(
'DB'
);
if
(
false
!==
$driver
&&
$driver
!==
'mysqli'
)
{
$this
->
markTestSkipped
(
'this test case is for mysqli only'
);
}
$this
->
resetSharedConn
();
parent
::
setUp
();
}
public
function
tearDown
()
{
parent
::
tearDown
();
$this
->
resetSharedConn
();
}
public
function
testDriverOptions
()
{
$driverOptions
=
array
(
\MYSQLI_OPT_CONNECT_TIMEOUT
=>
1
,
);
$connection
=
$this
->
getConnection
(
$driverOptions
);
$this
->
assertInstanceOf
(
"\Doctrine\DBAL\Driver\Mysqli\MysqliConnection"
,
$connection
);
}
/**
* @expectedException \Doctrine\DBAL\Driver\Mysqli\MysqliException
*/
public
function
testUnsupportedDriverOption
()
{
$this
->
getConnection
(
array
(
'hello'
=>
'world'
));
// use local infile
}
private
function
getConnection
(
array
$driverOptions
)
{
return
new
\Doctrine\DBAL\Driver\Mysqli\MysqliConnection
(
array
(
'host'
=>
$GLOBALS
[
'db_host'
],
'dbname'
=>
$GLOBALS
[
'db_name'
],
),
$GLOBALS
[
'db_username'
],
$GLOBALS
[
'db_password'
],
$driverOptions
);
}
}
\ No newline at end of file
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