1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Driver\PDOSqlsrv; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Driver\AbstractSQLServerDriver; |
23
|
|
|
use function sprintf; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The PDO-based Sqlsrv driver. |
27
|
|
|
* |
28
|
|
|
* @since 2.0 |
29
|
|
|
*/ |
30
|
|
|
class Driver extends AbstractSQLServerDriver |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
27 |
|
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) |
36
|
|
|
{ |
37
|
27 |
|
return new Connection( |
38
|
27 |
|
$this->_constructPdoDsn($params), |
39
|
27 |
|
$username, |
40
|
27 |
|
$password, |
41
|
27 |
|
$driverOptions |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructs the Sqlsrv PDO DSN. |
47
|
|
|
* |
48
|
|
|
* @param array $params |
49
|
|
|
* |
50
|
|
|
* @return string The DSN. |
51
|
|
|
*/ |
52
|
27 |
|
private function _constructPdoDsn(array $params) |
53
|
|
|
{ |
54
|
27 |
|
$dsn = 'sqlsrv:server='; |
55
|
|
|
|
56
|
27 |
|
if (isset($params['host'])) { |
57
|
27 |
|
$dsn .= $params['host']; |
58
|
|
|
} |
59
|
|
|
|
60
|
27 |
|
if (isset($params['port']) && !empty($params['port'])) { |
61
|
27 |
|
$dsn .= ',' . $params['port']; |
62
|
|
|
} |
63
|
|
|
|
64
|
27 |
|
if (isset($params['dbname'])) { |
65
|
27 |
|
$dsn .= ';Database=' . $params['dbname']; |
66
|
|
|
} |
67
|
|
|
|
68
|
27 |
|
if (isset($params['connectionOptions'])) { |
69
|
|
|
$dsn .= $this->getConnectionOptionsDsn($params['connectionOptions']); |
70
|
|
|
} |
71
|
|
|
|
72
|
27 |
|
return $dsn; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Converts a connection options array to the DSN |
77
|
|
|
* |
78
|
|
|
* @param string[] $connectionOptions |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
private function getConnectionOptionsDsn(array $connectionOptions) |
82
|
|
|
{ |
83
|
|
|
$connectionOptionsDsn = ''; |
84
|
|
|
|
85
|
|
|
foreach ($connectionOptions as $paramName => $paramValue) { |
86
|
|
|
$connectionOptionsDsn .= sprintf(';%s=%s', $paramName, $paramValue); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $connectionOptionsDsn; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
22 |
|
public function getName() |
96
|
|
|
{ |
97
|
22 |
|
return 'pdo_sqlsrv'; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|