1 | <?php |
---|
2 | /* |
---|
3 | * $Id$ |
---|
4 | * |
---|
5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
16 | * |
---|
17 | * This software consists of voluntary contributions made by many individuals |
---|
18 | * and is licensed under the LGPL. For more information, see |
---|
19 | * <http://www.doctrine-project.org>. |
---|
20 | */ |
---|
21 | |
---|
22 | namespace Doctrine\DBAL\Driver\PDOIbm; |
---|
23 | |
---|
24 | use Doctrine\DBAL\Connection; |
---|
25 | |
---|
26 | /** |
---|
27 | * Driver for the PDO IBM extension |
---|
28 | * |
---|
29 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
---|
30 | * @link www.doctrine-project.com |
---|
31 | * @since 1.0 |
---|
32 | * @version $Revision$ |
---|
33 | * @author Benjamin Eberlei <kontakt@beberlei.de> |
---|
34 | * @author Guilherme Blanco <guilhermeblanco@hotmail.com> |
---|
35 | * @author Jonathan Wage <jonwage@gmail.com> |
---|
36 | * @author Roman Borschel <roman@code-factory.org> |
---|
37 | */ |
---|
38 | class Driver implements \Doctrine\DBAL\Driver |
---|
39 | { |
---|
40 | /** |
---|
41 | * Attempts to establish a connection with the underlying driver. |
---|
42 | * |
---|
43 | * @param array $params |
---|
44 | * @param string $username |
---|
45 | * @param string $password |
---|
46 | * @param array $driverOptions |
---|
47 | * @return Doctrine\DBAL\Driver\Connection |
---|
48 | */ |
---|
49 | public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) |
---|
50 | { |
---|
51 | $conn = new \Doctrine\DBAL\Driver\PDOConnection( |
---|
52 | $this->_constructPdoDsn($params), |
---|
53 | $username, |
---|
54 | $password, |
---|
55 | $driverOptions |
---|
56 | ); |
---|
57 | return $conn; |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Constructs the MySql PDO DSN. |
---|
62 | * |
---|
63 | * @return string The DSN. |
---|
64 | */ |
---|
65 | private function _constructPdoDsn(array $params) |
---|
66 | { |
---|
67 | $dsn = 'ibm:'; |
---|
68 | if (isset($params['host'])) { |
---|
69 | $dsn .= 'HOSTNAME=' . $params['host'] . ';'; |
---|
70 | } |
---|
71 | if (isset($params['port'])) { |
---|
72 | $dsn .= 'PORT=' . $params['port'] . ';'; |
---|
73 | } |
---|
74 | $dsn .= 'PROTOCOL=TCPIP;'; |
---|
75 | if (isset($params['dbname'])) { |
---|
76 | $dsn .= 'DATABASE=' . $params['dbname'] . ';'; |
---|
77 | } |
---|
78 | |
---|
79 | return $dsn; |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * Gets the DatabasePlatform instance that provides all the metadata about |
---|
84 | * the platform this driver connects to. |
---|
85 | * |
---|
86 | * @return Doctrine\DBAL\Platforms\AbstractPlatform The database platform. |
---|
87 | */ |
---|
88 | public function getDatabasePlatform() |
---|
89 | { |
---|
90 | return new \Doctrine\DBAL\Platforms\DB2Platform; |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Gets the SchemaManager that can be used to inspect and change the underlying |
---|
95 | * database schema of the platform this driver connects to. |
---|
96 | * |
---|
97 | * @param Doctrine\DBAL\Connection $conn |
---|
98 | * @return Doctrine\DBAL\SchemaManager |
---|
99 | */ |
---|
100 | public function getSchemaManager(Connection $conn) |
---|
101 | { |
---|
102 | return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn); |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * Gets the name of the driver. |
---|
107 | * |
---|
108 | * @return string The name of the driver. |
---|
109 | */ |
---|
110 | public function getName() |
---|
111 | { |
---|
112 | return 'pdo_ibm'; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * Get the name of the database connected to for this driver. |
---|
117 | * |
---|
118 | * @param Doctrine\DBAL\Connection $conn |
---|
119 | * @return string $database |
---|
120 | */ |
---|
121 | public function getDatabase(\Doctrine\DBAL\Connection $conn) |
---|
122 | { |
---|
123 | $params = $conn->getParams(); |
---|
124 | return $params['dbname']; |
---|
125 | } |
---|
126 | } |
---|