Driver.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Doctrine\DBAL\Driver\PDOIbm;
  3. use Doctrine\DBAL\Driver\AbstractDB2Driver;
  4. use Doctrine\DBAL\Driver\PDOConnection;
  5. /**
  6. * Driver for the PDO IBM extension.
  7. */
  8. class Driver extends AbstractDB2Driver
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
  14. {
  15. return new PDOConnection(
  16. $this->_constructPdoDsn($params),
  17. $username,
  18. $password,
  19. $driverOptions
  20. );
  21. }
  22. /**
  23. * Constructs the IBM PDO DSN.
  24. *
  25. * @param mixed[] $params
  26. *
  27. * @return string The DSN.
  28. */
  29. private function _constructPdoDsn(array $params)
  30. {
  31. $dsn = 'ibm:';
  32. if (isset($params['host'])) {
  33. $dsn .= 'HOSTNAME=' . $params['host'] . ';';
  34. }
  35. if (isset($params['port'])) {
  36. $dsn .= 'PORT=' . $params['port'] . ';';
  37. }
  38. $dsn .= 'PROTOCOL=TCPIP;';
  39. if (isset($params['dbname'])) {
  40. $dsn .= 'DATABASE=' . $params['dbname'] . ';';
  41. }
  42. return $dsn;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function getName()
  48. {
  49. return 'pdo_ibm';
  50. }
  51. }