Driver.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\PDOSqlsrv;
  20. /**
  21. * The PDO-based Sqlsrv driver.
  22. *
  23. * @since 2.0
  24. */
  25. class Driver implements \Doctrine\DBAL\Driver
  26. {
  27. public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
  28. {
  29. return new Connection(
  30. $this->_constructPdoDsn($params),
  31. $username,
  32. $password,
  33. $driverOptions
  34. );
  35. }
  36. /**
  37. * Constructs the Sqlsrv PDO DSN.
  38. *
  39. * @return string The DSN.
  40. */
  41. private function _constructPdoDsn(array $params)
  42. {
  43. $dsn = 'sqlsrv:server=';
  44. if (isset($params['host'])) {
  45. $dsn .= $params['host'];
  46. }
  47. if (isset($params['port']) && !empty($params['port'])) {
  48. $dsn .= ',' . $params['port'];
  49. }
  50. if (isset($params['dbname'])) {;
  51. $dsn .= ';Database=' . $params['dbname'];
  52. }
  53. if (isset($params['MultipleActiveResultSets'])) {
  54. $dsn .= '; MultipleActiveResultSets=' . ($params['MultipleActiveResultSets'] ? 'true' : 'false');
  55. }
  56. return $dsn;
  57. }
  58. public function getDatabasePlatform()
  59. {
  60. return new \Doctrine\DBAL\Platforms\SQLServer2008Platform();
  61. }
  62. public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
  63. {
  64. return new \Doctrine\DBAL\Schema\SQLServerSchemaManager($conn);
  65. }
  66. public function getName()
  67. {
  68. return 'pdo_sqlsrv';
  69. }
  70. public function getDatabase(\Doctrine\DBAL\Connection $conn)
  71. {
  72. $params = $conn->getParams();
  73. return $params['dbname'];
  74. }
  75. }