Driver.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Doctrine\DBAL\Driver\OCI8;
  3. use Doctrine\DBAL\Driver\AbstractOracleDriver;
  4. use Doctrine\DBAL\Exception;
  5. use Doctrine\Deprecations\Deprecation;
  6. use const OCI_NO_AUTO_COMMIT;
  7. /**
  8. * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
  9. */
  10. class Driver extends AbstractOracleDriver
  11. {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
  16. {
  17. try {
  18. return new Connection(
  19. (string) $username,
  20. (string) $password,
  21. $this->_constructDsn($params),
  22. $params['charset'] ?? '',
  23. $params['sessionMode'] ?? OCI_NO_AUTO_COMMIT,
  24. $params['persistent'] ?? false
  25. );
  26. } catch (OCI8Exception $e) {
  27. throw Exception::driverException($this, $e);
  28. }
  29. }
  30. /**
  31. * Constructs the Oracle DSN.
  32. *
  33. * @param mixed[] $params
  34. *
  35. * @return string The DSN.
  36. */
  37. protected function _constructDsn(array $params)
  38. {
  39. return $this->getEasyConnectString($params);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. *
  44. * @deprecated
  45. */
  46. public function getName()
  47. {
  48. Deprecation::trigger(
  49. 'doctrine/dbal',
  50. 'https://github.com/doctrine/dbal/issues/3580',
  51. 'Driver::getName() is deprecated'
  52. );
  53. return 'oci8';
  54. }
  55. }