Driver.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. namespace Doctrine\DBAL\Driver\PDOIbm;
  22. use Doctrine\DBAL\Connection;
  23. /**
  24. * Driver for the PDO IBM extension
  25. *
  26. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  27. * @link www.doctrine-project.com
  28. * @since 1.0
  29. * @version $Revision$
  30. * @author Benjamin Eberlei <kontakt@beberlei.de>
  31. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  32. * @author Jonathan Wage <jonwage@gmail.com>
  33. * @author Roman Borschel <roman@code-factory.org>
  34. */
  35. class Driver implements \Doctrine\DBAL\Driver
  36. {
  37. /**
  38. * Attempts to establish a connection with the underlying driver.
  39. *
  40. * @param array $params
  41. * @param string $username
  42. * @param string $password
  43. * @param array $driverOptions
  44. * @return Doctrine\DBAL\Driver\Connection
  45. */
  46. public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
  47. {
  48. $conn = new \Doctrine\DBAL\Driver\PDOConnection(
  49. $this->_constructPdoDsn($params),
  50. $username,
  51. $password,
  52. $driverOptions
  53. );
  54. return $conn;
  55. }
  56. /**
  57. * Constructs the MySql PDO DSN.
  58. *
  59. * @return string The DSN.
  60. */
  61. private function _constructPdoDsn(array $params)
  62. {
  63. $dsn = 'ibm:';
  64. if (isset($params['host'])) {
  65. $dsn .= 'HOSTNAME=' . $params['host'] . ';';
  66. }
  67. if (isset($params['port'])) {
  68. $dsn .= 'PORT=' . $params['port'] . ';';
  69. }
  70. $dsn .= 'PROTOCOL=TCPIP;';
  71. if (isset($params['dbname'])) {
  72. $dsn .= 'DATABASE=' . $params['dbname'] . ';';
  73. }
  74. return $dsn;
  75. }
  76. /**
  77. * Gets the DatabasePlatform instance that provides all the metadata about
  78. * the platform this driver connects to.
  79. *
  80. * @return Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
  81. */
  82. public function getDatabasePlatform()
  83. {
  84. return new \Doctrine\DBAL\Platforms\DB2Platform;
  85. }
  86. /**
  87. * Gets the SchemaManager that can be used to inspect and change the underlying
  88. * database schema of the platform this driver connects to.
  89. *
  90. * @param Doctrine\DBAL\Connection $conn
  91. * @return Doctrine\DBAL\SchemaManager
  92. */
  93. public function getSchemaManager(Connection $conn)
  94. {
  95. return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn);
  96. }
  97. /**
  98. * Gets the name of the driver.
  99. *
  100. * @return string The name of the driver.
  101. */
  102. public function getName()
  103. {
  104. return 'pdo_ibm';
  105. }
  106. /**
  107. * Get the name of the database connected to for this driver.
  108. *
  109. * @param Doctrine\DBAL\Connection $conn
  110. * @return string $database
  111. */
  112. public function getDatabase(\Doctrine\DBAL\Connection $conn)
  113. {
  114. $params = $conn->getParams();
  115. return $params['dbname'];
  116. }
  117. }