Driver.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Driver\SQLSrv;
  20. /**
  21. * Driver for ext/sqlsrv.
  22. */
  23. class Driver implements \Doctrine\DBAL\Driver
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
  29. {
  30. if (!isset($params['host'])) {
  31. throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
  32. }
  33. if (!isset($params['dbname'])) {
  34. throw new SQLSrvException("Missing 'dbname' in configuration for sqlsrv driver.");
  35. }
  36. $serverName = $params['host'];
  37. if (isset($params['port'])) {
  38. $serverName .= ', ' . $params['port'];
  39. }
  40. $driverOptions['Database'] = $params['dbname'];
  41. $driverOptions['UID'] = $username;
  42. $driverOptions['PWD'] = $password;
  43. if (!isset($driverOptions['ReturnDatesAsStrings'])) {
  44. $driverOptions['ReturnDatesAsStrings'] = 1;
  45. }
  46. return new SQLSrvConnection($serverName, $driverOptions);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function getDatabasePlatform()
  52. {
  53. return new \Doctrine\DBAL\Platforms\SQLServer2008Platform();
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
  59. {
  60. return new \Doctrine\DBAL\Schema\SQLServerSchemaManager($conn);
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getName()
  66. {
  67. return 'sqlsrv';
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function getDatabase(\Doctrine\DBAL\Connection $conn)
  73. {
  74. $params = $conn->getParams();
  75. return $params['dbname'];
  76. }
  77. }