DB2Driver.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Driver\IBMDB2;
  20. use Doctrine\DBAL\Driver;
  21. use Doctrine\DBAL\Connection;
  22. /**
  23. * IBM DB2 Driver.
  24. *
  25. * @since 2.0
  26. * @author Benjamin Eberlei <kontakt@beberlei.de>
  27. */
  28. class DB2Driver implements Driver
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
  34. {
  35. if ( ! isset($params['protocol'])) {
  36. $params['protocol'] = 'TCPIP';
  37. }
  38. if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') {
  39. // if the host isn't localhost, use extended connection params
  40. $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
  41. ';DATABASE=' . $params['dbname'] .
  42. ';HOSTNAME=' . $params['host'] .
  43. ';PROTOCOL=' . $params['protocol'] .
  44. ';UID=' . $username .
  45. ';PWD=' . $password .';';
  46. if (isset($params['port'])) {
  47. $params['dbname'] .= 'PORT=' . $params['port'];
  48. }
  49. $username = null;
  50. $password = null;
  51. }
  52. return new DB2Connection($params, $username, $password, $driverOptions);
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function getDatabasePlatform()
  58. {
  59. return new \Doctrine\DBAL\Platforms\DB2Platform;
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function getSchemaManager(Connection $conn)
  65. {
  66. return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn);
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getName()
  72. {
  73. return 'ibm_db2';
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function getDatabase(\Doctrine\DBAL\Connection $conn)
  79. {
  80. $params = $conn->getParams();
  81. return $params['dbname'];
  82. }
  83. }