Driver.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 LGPL. 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 segfauls 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. public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
  32. {
  33. return new \Doctrine\DBAL\Driver\PDOConnection(
  34. $this->_constructPdoDsn($params),
  35. $username,
  36. $password,
  37. $driverOptions
  38. );
  39. }
  40. /**
  41. * Constructs the Oracle PDO DSN.
  42. *
  43. * @return string The DSN.
  44. */
  45. private function _constructPdoDsn(array $params)
  46. {
  47. $dsn = 'oci:';
  48. if (isset($params['host'])) {
  49. $dsn .= 'dbname=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
  50. '(HOST=' . $params['host'] . ')';
  51. if (isset($params['port'])) {
  52. $dsn .= '(PORT=' . $params['port'] . ')';
  53. } else {
  54. $dsn .= '(PORT=1521)';
  55. }
  56. if (isset($params['service']) && $params['service'] == true) {
  57. $dsn .= '))(CONNECT_DATA=(SERVICE_NAME=' . $params['dbname'] . ')))';
  58. } else {
  59. $dsn .= '))(CONNECT_DATA=(SID=' . $params['dbname'] . ')))';
  60. }
  61. } else {
  62. $dsn .= 'dbname=' . $params['dbname'];
  63. }
  64. if (isset($params['charset'])) {
  65. $dsn .= ';charset=' . $params['charset'];
  66. }
  67. return $dsn;
  68. }
  69. public function getDatabasePlatform()
  70. {
  71. return new \Doctrine\DBAL\Platforms\OraclePlatform();
  72. }
  73. public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
  74. {
  75. return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
  76. }
  77. public function getName()
  78. {
  79. return 'pdo_oracle';
  80. }
  81. public function getDatabase(\Doctrine\DBAL\Connection $conn)
  82. {
  83. $params = $conn->getParams();
  84. return $params['user'];
  85. }
  86. }