DB2Driver.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Doctrine\DBAL\Driver\IBMDB2;
  3. use Doctrine\DBAL\Driver\AbstractDB2Driver;
  4. /**
  5. * IBM DB2 Driver.
  6. */
  7. class DB2Driver extends AbstractDB2Driver
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
  13. {
  14. if (! isset($params['protocol'])) {
  15. $params['protocol'] = 'TCPIP';
  16. }
  17. if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') {
  18. // if the host isn't localhost, use extended connection params
  19. $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
  20. ';DATABASE=' . $params['dbname'] .
  21. ';HOSTNAME=' . $params['host'] .
  22. ';PROTOCOL=' . $params['protocol'] .
  23. ';UID=' . $username .
  24. ';PWD=' . $password . ';';
  25. if (isset($params['port'])) {
  26. $params['dbname'] .= 'PORT=' . $params['port'];
  27. }
  28. $username = null;
  29. $password = null;
  30. }
  31. return new DB2Connection($params, $username, $password, $driverOptions);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function getName()
  37. {
  38. return 'ibm_db2';
  39. }
  40. }