Driver.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\PDOOracle;
  20. use Doctrine\DBAL\Platforms;
  21. /**
  22. * PDO Oracle driver.
  23. *
  24. * WARNING: This driver gives us segfaults in our testsuites on CLOB and other
  25. * stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
  26. * which leads us to the recommendation to use the "oci8" driver to connect
  27. * to Oracle instead.
  28. */
  29. class Driver implements \Doctrine\DBAL\Driver
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
  35. {
  36. return new \Doctrine\DBAL\Driver\PDOConnection(
  37. $this->_constructPdoDsn($params),
  38. $username,
  39. $password,
  40. $driverOptions
  41. );
  42. }
  43. /**
  44. * Constructs the Oracle PDO DSN.
  45. *
  46. * @param array $params
  47. *
  48. * @return string The DSN.
  49. */
  50. private function _constructPdoDsn(array $params)
  51. {
  52. $dsn = 'oci:dbname=';
  53. if (isset($params['host']) && $params['host'] != '') {
  54. $dsn .= '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
  55. '(HOST=' . $params['host'] . ')';
  56. if (isset($params['port'])) {
  57. $dsn .= '(PORT=' . $params['port'] . ')';
  58. } else {
  59. $dsn .= '(PORT=1521)';
  60. }
  61. $database = 'SID=' . $params['dbname'];
  62. $pooled = '';
  63. if (isset($params['service']) && $params['service'] == true) {
  64. $database = 'SERVICE_NAME=' . $params['dbname'];
  65. }
  66. if (isset($params['pooled']) && $params['pooled'] == true) {
  67. $pooled = '(SERVER=POOLED)';
  68. }
  69. $dsn .= '))(CONNECT_DATA=(' . $database . ')' . $pooled . '))';
  70. } else {
  71. $dsn .= $params['dbname'];
  72. }
  73. if (isset($params['charset'])) {
  74. $dsn .= ';charset=' . $params['charset'];
  75. }
  76. return $dsn;
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function getDatabasePlatform()
  82. {
  83. return new \Doctrine\DBAL\Platforms\OraclePlatform();
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
  89. {
  90. return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function getName()
  96. {
  97. return 'pdo_oracle';
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function getDatabase(\Doctrine\DBAL\Connection $conn)
  103. {
  104. $params = $conn->getParams();
  105. return $params['user'];
  106. }
  107. }