|
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 LGPL. For more information, see |
|
17 * <http://www.doctrine-project.org>. |
|
18 */ |
|
19 |
|
20 namespace Doctrine\DBAL\Driver\IBMDB2; |
|
21 |
|
22 use Doctrine\DBAL\Driver, |
|
23 Doctrine\DBAL\Connection; |
|
24 |
|
25 /** |
|
26 * IBM DB2 Driver |
|
27 * |
|
28 * @since 2.0 |
|
29 * @author Benjamin Eberlei <kontakt@beberlei.de> |
|
30 */ |
|
31 class DB2Driver implements Driver |
|
32 { |
|
33 /** |
|
34 * Attempts to create a connection with the database. |
|
35 * |
|
36 * @param array $params All connection parameters passed by the user. |
|
37 * @param string $username The username to use when connecting. |
|
38 * @param string $password The password to use when connecting. |
|
39 * @param array $driverOptions The driver options to use when connecting. |
|
40 * @return Doctrine\DBAL\Driver\Connection The database connection. |
|
41 */ |
|
42 public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) |
|
43 { |
|
44 if ( !isset($params['schema']) ) { |
|
45 |
|
46 } |
|
47 |
|
48 if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') { |
|
49 // if the host isn't localhost, use extended connection params |
|
50 $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' . |
|
51 ';DATABASE=' . $params['dbname'] . |
|
52 ';HOSTNAME=' . $params['host'] . |
|
53 ';PORT=' . $params['port'] . |
|
54 ';PROTOCOL=' . $params['protocol'] . |
|
55 ';UID=' . $username . |
|
56 ';PWD=' . $password .';'; |
|
57 $username = null; |
|
58 $password = null; |
|
59 } |
|
60 |
|
61 return new DB2Connection($params, $username, $password, $driverOptions); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Gets the DatabasePlatform instance that provides all the metadata about |
|
66 * the platform this driver connects to. |
|
67 * |
|
68 * @return Doctrine\DBAL\Platforms\AbstractPlatform The database platform. |
|
69 */ |
|
70 public function getDatabasePlatform() |
|
71 { |
|
72 return new \Doctrine\DBAL\Platforms\DB2Platform; |
|
73 } |
|
74 |
|
75 /** |
|
76 * Gets the SchemaManager that can be used to inspect and change the underlying |
|
77 * database schema of the platform this driver connects to. |
|
78 * |
|
79 * @param Doctrine\DBAL\Connection $conn |
|
80 * @return Doctrine\DBAL\SchemaManager |
|
81 */ |
|
82 public function getSchemaManager(Connection $conn) |
|
83 { |
|
84 return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn); |
|
85 } |
|
86 |
|
87 /** |
|
88 * Gets the name of the driver. |
|
89 * |
|
90 * @return string The name of the driver. |
|
91 */ |
|
92 public function getName() |
|
93 { |
|
94 return 'ibm_db2'; |
|
95 } |
|
96 |
|
97 /** |
|
98 * Get the name of the database connected to for this driver. |
|
99 * |
|
100 * @param Doctrine\DBAL\Connection $conn |
|
101 * @return string $database |
|
102 */ |
|
103 public function getDatabase(\Doctrine\DBAL\Connection $conn) |
|
104 { |
|
105 $params = $conn->getParams(); |
|
106 return $params['dbname']; |
|
107 } |
|
108 } |