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.
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>.
20 namespace Doctrine\DBAL\Driver\IBMDB2;
22 use Doctrine\DBAL\Driver,
23 Doctrine\DBAL\Connection;
29 * @author Benjamin Eberlei <kontakt@beberlei.de>
31 class DB2Driver implements Driver
34 * Attempts to create a connection with the database.
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.
42 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
44 if ( ! isset($params['protocol'])) {
45 $params['protocol'] = 'TCPIP';
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 ';PROTOCOL=' . $params['protocol'] .
55 ';PWD=' . $password .';';
56 if (isset($params['port'])) {
57 $params['dbname'] .= 'PORT=' . $params['port'];
64 return new DB2Connection($params, $username, $password, $driverOptions);
68 * Gets the DatabasePlatform instance that provides all the metadata about
69 * the platform this driver connects to.
71 * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
73 public function getDatabasePlatform()
75 return new \Doctrine\DBAL\Platforms\DB2Platform;
79 * Gets the SchemaManager that can be used to inspect and change the underlying
80 * database schema of the platform this driver connects to.
82 * @param \Doctrine\DBAL\Connection $conn
83 * @return \Doctrine\DBAL\Schema\DB2SchemaManager
85 public function getSchemaManager(Connection $conn)
87 return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn);
91 * Gets the name of the driver.
93 * @return string The name of the driver.
95 public function getName()
101 * Get the name of the database connected to for this driver.
103 * @param \Doctrine\DBAL\Connection $conn
104 * @return string $database
106 public function getDatabase(\Doctrine\DBAL\Connection $conn)
108 $params = $conn->getParams();
109 return $params['dbname'];