Driver.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Doctrine\DBAL\Driver\PDOOracle;
  3. use Doctrine\DBAL\DBALException;
  4. use Doctrine\DBAL\Driver\AbstractOracleDriver;
  5. use Doctrine\DBAL\Driver\PDOConnection;
  6. use PDOException;
  7. /**
  8. * PDO Oracle driver.
  9. *
  10. * WARNING: This driver gives us segfaults in our testsuites on CLOB and other
  11. * stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
  12. * which leads us to the recommendation to use the "oci8" driver to connect
  13. * to Oracle instead.
  14. */
  15. class Driver extends AbstractOracleDriver
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
  21. {
  22. try {
  23. return new PDOConnection(
  24. $this->constructPdoDsn($params),
  25. $username,
  26. $password,
  27. $driverOptions
  28. );
  29. } catch (PDOException $e) {
  30. throw DBALException::driverException($this, $e);
  31. }
  32. }
  33. /**
  34. * Constructs the Oracle PDO DSN.
  35. *
  36. * @param mixed[] $params
  37. *
  38. * @return string The DSN.
  39. */
  40. private function constructPdoDsn(array $params)
  41. {
  42. $dsn = 'oci:dbname=' . $this->getEasyConnectString($params);
  43. if (isset($params['charset'])) {
  44. $dsn .= ';charset=' . $params['charset'];
  45. }
  46. return $dsn;
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function getName()
  52. {
  53. return 'pdo_oracle';
  54. }
  55. }