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.
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the MIT license. For more information, see
19 * <http://www.doctrine-project.org>.
22 namespace Doctrine\DBAL\Driver\PDOIbm;
24 use Doctrine\DBAL\Connection;
27 * Driver for the PDO IBM extension
29 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
30 * @link www.doctrine-project.com
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>
38 class Driver implements \Doctrine\DBAL\Driver
41 * Attempts to establish a connection with the underlying driver.
43 * @param array $params
44 * @param string $username
45 * @param string $password
46 * @param array $driverOptions
47 * @return \Doctrine\DBAL\Driver\Connection
49 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
51 $conn = new \Doctrine\DBAL\Driver\PDOConnection(
52 $this->_constructPdoDsn($params),
61 * Constructs the MySql PDO DSN.
63 * @return string The DSN.
65 private function _constructPdoDsn(array $params)
68 if (isset($params['host'])) {
69 $dsn .= 'HOSTNAME=' . $params['host'] . ';';
71 if (isset($params['port'])) {
72 $dsn .= 'PORT=' . $params['port'] . ';';
74 $dsn .= 'PROTOCOL=TCPIP;';
75 if (isset($params['dbname'])) {
76 $dsn .= 'DATABASE=' . $params['dbname'] . ';';
83 * Gets the DatabasePlatform instance that provides all the metadata about
84 * the platform this driver connects to.
86 * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
88 public function getDatabasePlatform()
90 return new \Doctrine\DBAL\Platforms\DB2Platform;
94 * Gets the SchemaManager that can be used to inspect and change the underlying
95 * database schema of the platform this driver connects to.
97 * @param \Doctrine\DBAL\Connection $conn
98 * @return \Doctrine\DBAL\Schema\DB2SchemaManager
100 public function getSchemaManager(Connection $conn)
102 return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn);
106 * Gets the name of the driver.
108 * @return string The name of the driver.
110 public function getName()
116 * Get the name of the database connected to for this driver.
118 * @param \Doctrine\DBAL\Connection $conn
119 * @return string $database
121 public function getDatabase(\Doctrine\DBAL\Connection $conn)
123 $params = $conn->getParams();
124 return $params['dbname'];